运行 节点 task/function 在每天的特定时间计算夏令时

Run Node task/function at specific time daily while accounting for Daylight Savings

我正在尝试在每天的特定时间(东部时间早上 7 点)运行 一个节点 task/function,而不考虑夏令时。我试过基于 cron 的包,但 cron 似乎没有考虑到它。该应用 运行 所在的服务器在 GMT/UTC 上,因此也需要考虑这一点。这是我当前的代码:

const schedule = require('node-schedule');
...
const j = schedule.scheduleJob('0 12 * * *', function(){
  bot.channels.get(getDefaultChannel().id).send("Hello!  Your daily fact for today is", { embed: generateEmbed(getRandomFact()) });
});

这工作正常,但由于我们刚刚提前一个小时,消息出现在早上 8 点而不是早上 7 点。

这是一个棘手的问题,我试过几种方法,我认为 Cron 库效果最好 (https://www.npmjs.com/package/cron)。您可以在 US/Eastern 时区的早上 7 点将工作安排到 运行。

"use strict";
var cron = require('cron');

var job1 = new cron.CronJob({
  cronTime: '0 7 * * *',
  onTick: function() {
    bot.channels.get(getDefaultChannel().id).send("Hello!  Your daily fact for today is", { embed: generateEmbed(getRandomFact()) });
  },
  start: true,
  timeZone: 'US/Eastern'
});