Skip to content

Commit

Permalink
add a test for correctly checking the final minute of a skipped DST r…
Browse files Browse the repository at this point in the history
…ange.
  • Loading branch information
GijsvandenHoven authored and intcreator committed Mar 5, 2023
1 parent eccad0c commit df420d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,14 @@ function CronTime(luxon) {
/**
* Component of checking if a CronJob time existed in a DateTime range skipped by DST.
* This subroutine assumes the jump touches at least 2 hours, but the jump does not necessarily fully contain these hours.
*
* @see _checkTimeInSkippedRange
*
* This is done by defining the minutes to check for the first and last hour,
* and checking all 60 minutes for any hours in between them.
*
* If any hour x minute combination is a valid time, true is returned.
* The endMinute x endHour combination is only checked with the 0th second, since the rest would be out of the range.
*/
_checkTimeInSkippedRangeMultiHour: function (
startMinute,
Expand Down
14 changes: 14 additions & 0 deletions tests/crontime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,20 @@ describe('crontime', () => {
jobInRange = cronTime._checkTimeInSkippedRange(startDate, endDate);
expect(jobInRange).toEqual(true);
});
it('Should not include seconds in the minute after the DST jump as part of the jump scan', () => {
const endDate = luxon.DateTime.fromISO('2023-01-01T16:00:00.000', {
zone: 'Europe/Amsterdam'
});
// 1 hour jump case
let startDate = endDate.minus({ hour: 1, second: 1 });
const cronTime = new cron.CronTime('1 5 16 * * *'); // at 16:00:01.
let jobInRange = cronTime._checkTimeInSkippedRange(startDate, endDate);
expect(jobInRange).toEqual(false);
// 'quirky' jump case
startDate = endDate.minus({ hour: 1, minute: 45, second: 1 });
jobInRange = cronTime._checkTimeInSkippedRange(startDate, endDate);
expect(jobInRange).toEqual(false);
});
it('Should correctly scan time periods as if they are DST jumps, full hour jumps', () => {
let endDate = luxon.DateTime.fromISO('2023-01-01T16:00:00.000', {
zone: 'Europe/Amsterdam'
Expand Down

0 comments on commit df420d7

Please sign in to comment.