Skip to content

Regression in 5.3.0 β€” endDate is no longer inclusive, leading to missing occurrencesΒ #385

@mikaelkurek

Description

@mikaelkurek

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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions