maennchen / crontab

Parse Cron Expressions, Compose Cron Expression Strings and Caluclate Execution Dates.
https://hex.pm/packages/crontab
MIT License
91 stars 32 forks source link

Expressions are not being properly evaluated #119

Closed mustela closed 9 months ago

mustela commented 9 months ago

Hey there! Wondering if Im doing something wrong or there is a bug here.

Crontab.Scheduler.get_next_run_date(~e[*/2 * * * *], ~N[2023-12-02 14:40:00.298713])
{:ok, ~N[2023-12-02 14:42:00]}

Crontab.Scheduler.get_next_run_date(~e[*/3 * * * *], ~N[2023-12-02 14:40:00.298713])
{:ok, ~N[2023-12-02 14:42:00]}

Crontab.Scheduler.get_next_run_date(~e[*/4 * * * *], ~N[2023-12-02 14:40:00.298713])
{:ok, ~N[2023-12-02 14:44:00]}

On the 3 minutes interval, Im getting a wrong minute number.

And more random results

 Crontab.Scheduler.get_next_run_date(~e[*/4 * * * * *], ~N[2023-12-02 14:50:01.989811])
{:ok, ~N[2023-12-02 14:52:00]}

Any clue?

maennchen commented 9 months ago

@mustela Can you describe to me why you think that this result is wrong?

Crontab.Scheduler.get_next_run_date(~e[*/2 * * * *], ~N[2023-12-02 14:40:00.298713])
{:ok, ~N[2023-12-02 14:42:00]}

The minute 42 is the first minute after 40 that is divisible by two. (factor 21)

Crontab.Scheduler.get_next_run_date(~e[*/3 * * * *], ~N[2023-12-02 14:40:00.298713])
{:ok, ~N[2023-12-02 14:42:00]}

The minute 42 is the first minute after 40 that is divisible by three. (factor 14)

Crontab.Scheduler.get_next_run_date(~e[*/4 * * * *], ~N[2023-12-02 14:40:00.298713])
{:ok, ~N[2023-12-02 14:44:00]}

The minute 44 is the first minute after 40 that is divisible by four. (factor 11)

Crontab.Scheduler.get_next_run_date(~e[*/4 * * * * *], ~N[2023-12-02 14:50:01.989811])
{:ok, ~N[2023-12-02 14:52:00]}

The minute 52 is the first minute after 50 that is divisible by four. (factor 13)

Therefore this all looks good to me.

For context: */n is the same as 0/n and specifies that the date part must keep the following constraint: date_part % n == 0.

mustela commented 9 months ago

Forget about it. This is why you shouldn't have to code until very late. 😓

Thanks a lot for your quick response!