-
Notifications
You must be signed in to change notification settings - Fork 163
Description
Hi! π
After upgrading from [email protected] to 5.3.0, I noticed a regression where no occurrences are returned when they should be β specifically right at the endDate boundary.
This breaks expected behavior where endDate is supposed to be inclusive (or at least detect an occurrence exactly at that timestamp). This affects expressions that match exactly on a second or minute.
β Working in 4.9.0
Example: CRON every second (*/1 * * * * *)
import { CronDate, parseExpression } from 'cron-parser';
const cron = '*/1 * * * * *';
let currentDate = new Date(Math.ceil(Date.now() / 1000) * 1000);
const endDate = new Date(currentDate.getTime() + 1000); // +1s
const startDate = currentDate;
console.log('End Date: ' + endDate.toISOString());
setTimeout(() => {
currentDate = new Date();
console.log('Current Date: ' + currentDate.toISOString());
const options = {
currentDate: new Date(currentDate.getTime() - 1),
startDate,
endDate,
utc: false,
iterator: false,
};
const expr = parseExpression(cron, options);
if (expr.hasNext()) {
console.log(expr.next().toISOString()); // β
One occurrence found
}
}, 900);
Output (v4.9.0):
End Date: 2025-07-28T12:01:02.000Z
Current Date: 2025-07-28T12:01:01.011Z
2025-07-28T12:01:02.000Z β
β Same logic in 5.3.0:
import {
CronExpressionOptions,
CronDate,
CronExpressionParser,
} from 'cron-parser';
let cron = '*/1 * * * * *';
let currentDate = new Date(Math.ceil(Date.now() / 1000) * 1000);
const endDate = new Date(currentDate.getTime() + 1000);
const startDate = currentDate;
console.log('End Date: ' + endDate.toISOString());
setTimeout(() => {
currentDate = new Date();
console.log('Current Date: ' + currentDate.toISOString());
const options: CronExpressionOptions = {
currentDate: new Date(currentDate.getTime() - 1),
startDate,
endDate,
};
const expr = CronExpressionParser.parse(cron, options);
if (expr.hasNext()) {
console.log(expr.next().toISOString());
}
}, 900);
Output (v5.3.0):
End Date: 2025-07-28T12:01:10.000Z
Current Date: 2025-07-28T12:01:09.152Z
(no output) β
Same issue happens when switching to a minute-based CRON (cron '0 */1 * * * *')
π Suspected Issue
The occurrence exactly at endDate
(e.g., 2025-07-28T12:01:10.000Z) is now ignored in 5.3.0, while 4.9.0 includes it as a valid result. This is a regression or at least a behavioral change from earlier versions.
π Request
Can you clarify if this change is intentional ?
If not, could endDate
behavior be restored ?
Thank you for maintaining this project β it's been very useful!
Here the code I used to test :
https://playcode.io/2475511 for v.4.9.0
https://playcode.io/2475510 for v5.3.0