diff --git a/lib/crontab/scheduler.ex b/lib/crontab/scheduler.ex index ae91b51..8bc8d72 100644 --- a/lib/crontab/scheduler.ex +++ b/lib/crontab/scheduler.ex @@ -286,7 +286,7 @@ defmodule Crontab.Scheduler do defp correct_date(:year, date, :decrement), do: date |> DateHelper.dec_year |> DateHelper.end_of(:year) |> DateHelper.beginning_of(:second) @spec clean_date(NaiveDateTime.t, :seconds | :microseconds) :: NaiveDateTime.t - defp clean_date(date = %NaiveDateTime{microsecond: {0,0}}, :microseconds), do: date + defp clean_date(date = %NaiveDateTime{microsecond: {0, _}}, :microseconds), do: date defp clean_date(date = %NaiveDateTime{}, :microseconds) do date |> Map.put(:microsecond, {0,0}) diff --git a/test/crontab/scheduler_test.exs b/test/crontab/scheduler_test.exs index 32df13a..9a712e1 100644 --- a/test/crontab/scheduler_test.exs +++ b/test/crontab/scheduler_test.exs @@ -27,6 +27,14 @@ defmodule Crontab.SchedulerTest do assert get_next_run_date(%Crontab.CronExpression{minute: [16]}, ~N[2002-01-13 23:00:07]) == {:ok, ~N[2002-01-13 23:16:00]} end + test "check cron expression for second" do + assert get_next_run_date(%Crontab.CronExpression{extended: true, second: [{:/, :*, 3}]}, ~N[2002-01-13 23:00:06]) == {:ok, ~N[2002-01-13 23:00:06]} + end + + test "check cron expression given microseconds" do + assert get_next_run_date(%Crontab.CronExpression{extended: true, second: [{:/, :*, 3}]}, ~N[2002-01-13 23:00:06.00]) == {:ok, ~N[2002-01-13 23:00:06]} + end + test "check combined" do assert get_next_run_date(%Crontab.CronExpression{minute: [3], hour: [7], day: [27], month: [2]}, ~N[2002-01-13 23:00:07]) == {:ok, ~N[2002-02-27 07:03:00]} end