breejs / later

*Maintained fork of Later.* A javascript library for defining recurring schedules and calculating future (or past) occurrences for them. Includes support for using English phrases and Cron schedules. Works in Node and in the browser.
https://breejs.github.io/later/
MIT License
136 stars 13 forks source link

[fix] `next` seems to produce erroneous results esp around the full hour #31

Closed chandru89new closed 1 year ago

chandru89new commented 1 year ago

Describe the bug

Actual behavior

When using next on a cron expression (eg */13 * * * * -> every 13 minutes), it seems to generate occurrences that are shorter than 13 minutes every once in a while.

Eg:

const later = require('@breejs/later')
const cron = '*/13 * * * *'

const sched = later.parse.cron(cron)
const nexts = later.schedule(sched).next(11, new Date(2022,10,10,05,00))
console.log(nexts)

produces:

[
  2022-11-10T05:00:00.000Z,
  2022-11-10T05:13:00.000Z,
  2022-11-10T05:26:00.000Z,
  2022-11-10T05:39:00.000Z,
  2022-11-10T05:52:00.000Z,
  2022-11-10T06:00:00.000Z,
  2022-11-10T06:13:00.000Z,
  2022-11-10T06:26:00.000Z,
  2022-11-10T06:39:00.000Z,
  2022-11-10T06:52:00.000Z,
  2022-11-10T07:00:00.000Z
]

After 5:52:00, it should be 6:05:00 and after 6:52:00 (which technically should not be a possible time in the schedule), it should be 7:05:00.

Expected behavior

It should compute the right time for the interval.

Code to reproduce

const later = require('@breejs/later')
const cron = '*/13 * * * *'

const sched = later.parse.cron(cron)
const nexts = later.schedule(sched).next(11, new Date(2022,10,10,05,00))
console.log(nexts)

Checklist

chandru89new commented 1 year ago

Sorry about this, but closing this because it's how cron works by design and not a bug of this library.