31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
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 * * 1-5' : '0 6 * * 1-5';
|
|
const closeJob = new CronJob(closeTime, async () => {
|
|
if (channel) {
|
|
await channel.send('미국 주식 시장이 닫혔습니다.');
|
|
}
|
|
}, null, true, 'Asia/Seoul');
|
|
|
|
// 작업 시작
|
|
openJob.start();
|
|
closeJob.start();
|
|
}
|