harrisiirak / cron-parser

Node.js library for parsing crontab instructions
MIT License
1.32k stars 156 forks source link

Incorrect Next Interval #266

Closed iamsid closed 2 years ago

iamsid commented 2 years ago

Hi. I have a cron expression 0 0 10 ? * MON which translates to "at 10 am only on Monday" (https://crontab.cronhub.io/). Passing this to cron-parser to fetch the next interval right now (11th April 2022) is returning 25th April 2022. Although, there is a Monday on 18th.

I can see similar "rounding" of times as well. Running an expression like 0 0/2 * 1/1 * ? * (run every 2 min) on say 11:08:23am returns 11:12:00, instead of 11:10:00.

I don't have much understanding of the workings of cron expressions, but I would like to see 18th or 11:10 as output. Am I missing something or is it a bug?

harrisiirak commented 2 years ago

Hi @iamsid!

Passing this to cron-parser to fetch the next interval right now (11th April 2022) is returning 25th April 2022. Although, there is a Monday on 18th.

Do you have example code for that case? In my local environment it will generate dates that are expected.

Mon Apr 18 2022 10:00:00 GMT+0300 (Eastern European Summer Time) Mon Apr 25 2022 10:00:00 GMT+0300 (Eastern European Summer Time) Mon May 02 2022 10:00:00 GMT+0300 (Eastern European Summer Time) Mon May 09 2022 10:00:00 GMT+0300 (Eastern European Summer Time) Mon May 16 2022 10:00:00 GMT+0300 (Eastern European Summer Time) Mon May 23 2022 10:00:00 GMT+0300 (Eastern European Summer Time) Mon May 30 2022 10:00:00 GMT+0300 (Eastern European Summer Time) Mon Jun 06 2022 10:00:00 GMT+0300 (Eastern European Summer Time)

I can see similar "rounding" of times as well. Running an expression like 0 0/2 1/1 ? * (run every 2 min) on say 11:08:23am returns 11:12:00, instead of 11:10:00.

Also not completely sure how to replicate this locally. My local time: Mon Apr 11 2022 15:46:53 GMT+0300 (Eastern European Summer Time)

Mon Apr 11 2022 15:48:00 GMT+0300 (Eastern European Summer Time) Mon Apr 11 2022 15:50:00 GMT+0300 (Eastern European Summer Time) Mon Apr 11 2022 15:52:00 GMT+0300 (Eastern European Summer Time) Mon Apr 11 2022 15:54:00 GMT+0300 (Eastern European Summer Time) Mon Apr 11 2022 15:56:00 GMT+0300 (Eastern European Summer Time)

iamsid commented 2 years ago

Hi @harrisiirak Looks like it was an incorrect configuration on my end. I was running the next() function twice. Sorry for the inconvenience.