When currentDate matches given cron expression, CronDate will miss current event
chengB12 opened this issue · 7 comments
import cronParser from 'cron-parser'
const cron = cronParser.parseExpression('*/5 * * * *', { currentDate: new Date('2020-01-02T00:00:00.000Z') })
cron.next() => '2020-01-02T00:05:00.000Z'
cron.prev() => '2020-01-01T23:55:00.000Z'
if I am checking if there should be a match on '2020-01-02T00:00:00.000Z', we are out of luck
Hi @chengB12!
Which version of cron-parser
you are currently using? The latest version produces expected output:
const interval = parseExpression('*/5 * * * *', { currentDate: new Date('2020-01-02T00:00:00.000Z') });
console.log(interval.next().toISOString()); // 2020-01-02T00:05:00.000Z
console.log(interval.prev().toISOString()); // 2020-01-02T00:00:00.000Z
Hi @chengB12!
Which version of
cron-parser
you are currently using? The latest version produces expected output:const interval = parseExpression('*/5 * * * *', { currentDate: new Date('2020-01-02T00:00:00.000Z') }); console.log(interval.next().toISOString()); // 2020-01-02T00:05:00.000Z console.log(interval.prev().toISOString()); // 2020-01-02T00:00:00.000Z
I use "cron-parser": "^4.6.0", I still see this issue
Hi @harrisiirak ,
I see the same issue, current date itself is not present in the outcome
I expect that first call of interval.next returns currentDate, is that right expectation?
Now I'm actually seeing the issue (for some reason I was thinking that there is something wrong with prev call behaviour). Yes @klumba12, your assumption is correct, it shouldn't skip current date if it matches and return it. I'll file it as a bug.
After some investigation I'll take my previous comment back: this is currently expected behaviour. If currentDate
is already exactly matching with given cron pattern, next matching date after that will be matched when next
is called.
If the date is set to 2020-01-02T00:00:00.000Z
and we call next
, then currently the iteration logic expects that match has already happened (at 00:00
) and the next date (00:05
) after that will be matched instead, accordingly defined pattern.
Sorry about the confusion! This will be wontfix as there will be no plans to change this behaviour.