import { CronJob } from 'cron'; import { isDaylightSavingTime } from '../feature/utility.js'; export function initializeCronJobs(client) { const channel = client.channels.cache.get(process.env.CH_FINANCE); // 미국 주식 시장 개장 시간 (월~금) const openTime = isDaylightSavingTime() ? '30 22 * * 1-5' : '30 23 * * 1-5'; const openJob = new CronJob(openTime, async () => { if (channel) { const isDST = isDaylightSavingTime(); const dstMessage = isDST ? '(서머타임 적용)' : '(서머타임 미적용)'; await channel.send(`미국 주식 시장이 열렸습니다. ${dstMessage}`); } }, null, true, 'Asia/Seoul'); // 미국 주식 시장 폐장 시간 (월~금) → 한국 시간 화~토 새벽에 실행 const closeTime = isDaylightSavingTime() ? '0 5 * * 2-6' : '0 6 * * 2-6'; const closeJob = new CronJob(closeTime, async () => { if (channel) { await channel.send('미국 주식 시장이 닫혔습니다.'); } }, null, true, 'Asia/Seoul'); // 작업 시작 openJob.start(); closeJob.start(); }