Skip to content

Commit

Permalink
Merge pull request #1 from sk-t/feature/rename_test_file
Browse files Browse the repository at this point in the history
Rename test file & fix divider by 0 issue
  • Loading branch information
maennchen authored Dec 22, 2016
2 parents c7f7f7d + b65916d commit d288f8e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
24 changes: 12 additions & 12 deletions lib/crontab/cron_date_checker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ defmodule Crontab.CronDateChecker do
def matches_date(_, [], _), do: false
def matches_date(interval, [condition = {:/, _} | tail], execution_date) do
values = get_interval_value(interval, execution_date)
if matches_specific_date(values, condition) do
if matches_specific_date(interval, values, condition) do
true
else
matches_date(interval, tail, execution_date)
end
end
def matches_date(interval, [condition = {:-, _, _} | tail], execution_date) do
values = get_interval_value(interval, execution_date)
if matches_specific_date(values, condition) do
if matches_specific_date(interval, values, condition) do
true
else
matches_date(interval, tail, execution_date)
end
end
def matches_date(interval, [number | tail], execution_date) when is_integer(number) do
values = get_interval_value(interval, execution_date)
if matches_specific_date(values, number) do
if matches_specific_date(interval, values, number) do
true
else
matches_date(interval, tail, execution_date)
Expand All @@ -57,29 +57,29 @@ defmodule Crontab.CronDateChecker do
matches_date(interval, conditions, execution_date) && matches_date(tail, execution_date)
end

defp matches_specific_date([], _), do: false
defp matches_specific_date([head_value | tail_values], condition = {:-, min, max}) do
defp matches_specific_date(_, [], _), do: false
defp matches_specific_date(interval, [head_value | tail_values], condition = {:-, min, max}) do
if head_value >= min && head_value <= max do
true
else
matches_specific_date(tail_values, condition)
matches_specific_date(interval, tail_values, condition)
end
end
defp matches_specific_date([0 | tail_values], condition = {:/, _}) do
matches_specific_date(tail_values, condition)
defp matches_specific_date(:weekday, [0 | tail_values], condition = {:/, _}) do
matches_specific_date(:weekday, tail_values, condition)
end
defp matches_specific_date([head_value | tail_values], condition = {:/, divider}) do
defp matches_specific_date(interval, [head_value | tail_values], condition = {:/, divider}) do
if rem(head_value, divider) == 0 do
true
else
matches_specific_date(tail_values, condition)
matches_specific_date(interval, tail_values, condition)
end
end
defp matches_specific_date([head_value | tail_values], number) when is_integer(number) do
defp matches_specific_date(interval, [head_value | tail_values], number) when is_integer(number) do
if head_value == number do
true
else
matches_specific_date(tail_values, number)
matches_specific_date(interval, tail_values, number)
end
end

Expand Down
4 changes: 0 additions & 4 deletions lib/crontab/cron_scheduler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ defmodule Crontab.CronScheduler do
end
def get_next_run_date(conditions, date, max_runs) when max_runs > 0 do
{status, corrected_date} = search_and_correct_date(conditions, date);
#IO.puts "next"
#IO.inspect corrected_date
case status do
:found -> {:ok, corrected_date}
_ -> get_next_run_date(conditions, corrected_date, max_runs - 1)
Expand All @@ -39,8 +37,6 @@ defmodule Crontab.CronScheduler do
end

defp search_and_correct_date([{interval, conditions} | tail], date) do
#IO.puts "search"
#IO.inspect date
if matches_date(interval, conditions, date) do
search_and_correct_date(tail, date)
else
Expand Down
File renamed without changes.

0 comments on commit d288f8e

Please sign in to comment.