Skip to content

Commit

Permalink
Use DateTime.from_naive/2 to determine ambiguity
Browse files Browse the repository at this point in the history
  • Loading branch information
shaolang committed Feb 12, 2024
1 parent 22b21bd commit b71ead2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
19 changes: 4 additions & 15 deletions lib/crontab/date_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -309,21 +309,10 @@ defmodule Crontab.DateHelper do
false ->
candidate

true ->
adj_plus_1h = DateTime.add(adjusted, 1, :hour)

case adj_plus_1h.std_offset == adjusted.std_offset do
true ->
adjusted

_ ->
# the one hour at end of daylight savings with ambiguous timezone
# return datetime with the standard (not daylight savings) timezone
%DateTime{
adjusted
| std_offset: adj_plus_1h.std_offset,
zone_abbr: adj_plus_1h.zone_abbr
}
_ ->
case DateTime.from_naive(DateTime.to_naive(adjusted), adjusted.time_zone) do
{:ambiguous, _, target} -> target
{:ok, target} -> target
end
end
end
Expand Down
1 change: 0 additions & 1 deletion test/crontab/date_helper_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ defmodule Crontab.DateHelperTest do
end
end

# , {:minute, ~T[01:00:59]}, {:hour, ~T[01:59:59]}] do
for {unit, hour, minute, second} <- [
{:second, 1, 0, 0},
{:minute, 1, 0, 59},
Expand Down

0 comments on commit b71ead2

Please sign in to comment.