Skip to content

prev() wrongly skipping back an extra day on first call in specific case of time change #378

@ellis

Description

@ellis

Here is sample code for v5.1.1 that demonstrates the skipped day:

import { CronExpressionParser } from 'cron-parser';
var interval = CronExpressionParser.parse("0 2 * * *", {tz: "America/New_York", currentDate: "2020-03-08T03:01:00.000-04:00"});
console.log(interval.prev().toISOString())
// 2020-03-07T07:00:00.000Z - ERROR: should be 2020-03-08T07:00:00.000Z
console.log(interval.next().toISOString())
// 2020-03-08T07:00:00.000Z

Here is another example where the error is even clearer:

import { CronExpressionParser } from 'cron-parser';
const interval = CronExpressionParser.parse("0 2 * * *", {tz: "America/New_York", currentDate: "2020-03-08T03:01:00.000-04:00"});
console.log(interval.next().toISOString())
// 2020-03-09T06:00:00.000Z
console.log(interval.prev().toISOString())
// 2020-03-07T07:00:00.000Z - ERROR: should be 2020-03-08T07:00:00.000Z

The equivalent code had previously worked in 4.9.0; my unit tests caught the error after I upgraded cron-parser today.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions