Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date helper datetime support #129

Merged
merged 15 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/crontab/date_checker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ defmodule Crontab.DateChecker do
true

"""
@spec matches_date?(cron_expression :: CronExpression.t(), date :: date) :: boolean | no_return
@spec matches_date?(cron_expression :: CronExpression.t(), date :: DateHelper.date()) ::
maennchen marked this conversation as resolved.
Show resolved Hide resolved
boolean | no_return
def matches_date?(cron_expression_or_condition_list, date)

def matches_date?(%CronExpression{reboot: true}, _),
Expand All @@ -39,7 +40,10 @@ defmodule Crontab.DateChecker do
|> matches_date?(execution_date)
end

@spec matches_date?(condition_list :: CronExpression.condition_list(), date :: date) :: boolean
@spec matches_date?(
condition_list :: CronExpression.condition_list(),
date :: DateHelper.date()
) :: boolean
def matches_date?([], _), do: true

def matches_date?([{interval, conditions} | tail], execution_date) do
Expand All @@ -61,7 +65,7 @@ defmodule Crontab.DateChecker do
@spec matches_date?(
interval :: CronExpression.interval(),
condition_list :: CronExpression.condition_list(),
date :: date
date :: DateHelper.date()
) :: boolean
def matches_date?(_, [:* | _], _), do: true
def matches_date?(_, [], _), do: false
Expand All @@ -80,7 +84,7 @@ defmodule Crontab.DateChecker do
interval :: CronExpression.interval(),
values :: [CronExpression.time_unit()],
condition :: CronExpression.value(),
date :: date
date :: DateHelper.date()
) :: boolean
defp matches_specific_date?(_, [], _, _), do: false
defp matches_specific_date?(_, _, :*, _), do: true
Expand Down Expand Up @@ -171,7 +175,7 @@ defmodule Crontab.DateChecker do
end
end

@spec get_interval_value(interval :: CronExpression.interval(), date :: date) :: [
@spec get_interval_value(interval :: CronExpression.interval(), date :: DateHelper.date()) :: [
CronExpression.time_unit()
]
defp get_interval_value(:second, %{second: second}), do: [second]
Expand Down