You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue seems be be that tz-offset lib tries to apply the offset for a timezone in the local system time, and node-cron then gets the minute, hour, day, etc. in the local system time with getHours() etc. so tasks get missed or repeated when the hour doesn't exist or is repeated in the system local time.
For example if the system timezone is "Europe/London" which observes DST, scheduling tasks in another timezone (for example "Asia/Tokyo", which doesn't observe DST, so unrelated to #157):
consttzoffset=require('tz-offset');// tz-offset@0.0.2constdate0=newDate('2019-03-30T23:30:00.000Z');constdate1=newDate('2019-03-31T00:30:00.000Z');constdate2=newDate('2019-03-31T01:30:00.000Z');constdate3=newDate('2019-03-31T02:30:00.000Z');constdate4=newDate('2019-10-26T23:30:00.000Z');constdate5=newDate('2019-10-27T00:30:00.000Z');constdate6=newDate('2019-10-27T01:30:00.000Z');constdate7=newDate('2019-10-27T02:30:00.000Z');constdate0Tokyo=tzoffset.timeAt(date0,'Asia/Tokyo');constdate1Tokyo=tzoffset.timeAt(date1,'Asia/Tokyo');constdate2Tokyo=tzoffset.timeAt(date2,'Asia/Tokyo');constdate3Tokyo=tzoffset.timeAt(date3,'Asia/Tokyo');constdate4Tokyo=tzoffset.timeAt(date4,'Asia/Tokyo');constdate5Tokyo=tzoffset.timeAt(date5,'Asia/Tokyo');constdate6Tokyo=tzoffset.timeAt(date6,'Asia/Tokyo');constdate7Tokyo=tzoffset.timeAt(date7,'Asia/Tokyo');constprintLocalTime=date=>console.log(`(system local time) hour: ${date.getHours()}, minute: ${date.getMinutes()}, second: ${date.getSeconds()}`)printLocalTime(date0Tokyo);// (system local time) hour: 9, minute: 30, second: 0printLocalTime(date1Tokyo);// (system local time) hour: 10, minute: 30, second: 0printLocalTime(date2Tokyo);// (system local time) hour: 10, minute: 30, second: 0printLocalTime(date3Tokyo);// (system local time) hour: 11, minute: 30, second: 0printLocalTime(date4Tokyo);// (system local time) hour: 7, minute: 30, second: 0printLocalTime(date5Tokyo);// (system local time) hour: 8, minute: 30, second: 0printLocalTime(date6Tokyo);// (system local time) hour: 10, minute: 30, second: 0printLocalTime(date7Tokyo);// (system local time) hour: 11, minute: 30, second: 0
The issue seems be be that tz-offset lib tries to apply the offset for a timezone in the local system time, and node-cron then gets the minute, hour, day, etc. in the local system time with getHours() etc. so tasks get missed or repeated when the hour doesn't exist or is repeated in the system local time.
https://github.com/node-cron/tz-offset/blob/50f2e1cde8447b332215a5deee09127cd30088eb/src/tz-offset.js#L15-L24
node-cron/src/time-matcher.js
Lines 21 to 33 in 2a39703
For example if the system timezone is "Europe/London" which observes DST, scheduling tasks in another timezone (for example "Asia/Tokyo", which doesn't observe DST, so unrelated to #157):
Changing
timeAt
to apply the offset in UTC time:and
time-matcher.js
to use getUTCHours() etc. seems to fix the issue:The text was updated successfully, but these errors were encountered: