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 openJob = new CronJob('30 22-23 * * 1-5', async (now) => { const isDST = isDaylightSavingTime(); const expectedHour = isDST ? 22 : 23; if (now.getHours() === expectedHour) { const dstMessage = isDST ? '(서머타임 적용)' : '(서머타임 미적용)'; await channel.send(`미국 주식 시장이 열렸습니다. ${dstMessage}`); } }, null, true, 'Asia/Seoul'); const closeJob = new CronJob('0 5-6 * * 2-6', async (now) => { const isDST = isDaylightSavingTime(); const expectedHour = isDST ? 5 : 6; if (now.getHours() === expectedHour) { await channel.send('미국 주식 시장이 닫혔습니다.'); } }, null, true, 'Asia/Seoul'); // 작업 시작 openJob.start(); closeJob.start(); }