maennchen / crontab

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

Adding microsend precision changes the result #45

Closed towhans closed 7 years ago

towhans commented 7 years ago

Both these tests pass which is kind of weird. They should yield the same results but don't. Adding microsend precision changes the result.

test "check cron expression for minute overlap w/ micro" do
    assert get_next_run_date(%Crontab.CronExpression{minute: [16]}, ~N[2002-01-13 23:16:00.00]) == {:ok, ~N[2002-01-14 00:16:00]}
end

test "check cron expression for minute overlap w/o micto" do
    assert get_next_run_date(%Crontab.CronExpression{minute: [16]}, ~N[2002-01-13 23:16:00]) == {:ok, ~N[2002-01-13 23:16:00]}
end 

Maybe the root cause can is this:

iex(3)>  ~N[2002-01-13 23:16:00.00] ==  ~N[2002-01-13 23:16:00]
false
towhans commented 7 years ago

This seems to work:

iex(4)> NaiveDateTime.compare(  ~N[2002-01-13 23:16:00.00] ,  ~N[2002-01-13 23:16:00] )
:eq
maennchen commented 7 years ago

@towhans Thanks for the report. I see where the error comes from. There is a wrong pattern match for the clean_date function.

https://github.com/jshmrtn/crontab/blob/master/lib/crontab/scheduler.ex#L289

maennchen commented 7 years ago

@towhans Could you check if the PR #46 solves the issue for you?