Skip to content

Commit 82bf612

Browse files
authored
Merge pull request #16 from bgentry/feature/timezone-support-test-cases
Feature/timezone support test cases
2 parents 34f58ff + 99bcc71 commit 82bf612

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

test/timezone_test.exs

+82-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ defmodule RecurringEvents.TimezoneTest do
44
alias RecurringEvents, as: RR
55

66
if Code.ensure_loaded?(Timex) do
7-
test "should handle timezones if Timex available" do
7+
test "should handle timezones at the fall DST boundary" do
88
time = Timex.to_datetime({{2018, 11, 2}, {5, 0, 0}}, "America/Los_Angeles")
99

1010
result =
@@ -21,6 +21,87 @@ defmodule RecurringEvents.TimezoneTest do
2121
)
2222
end
2323

24+
@doc """
25+
From RFC 5545:
26+
27+
> If, based on the definition of the referenced time zone, the local
28+
> time described occurs more than once (when changing from daylight
29+
> to standard time), the DATE-TIME value refers to the first
30+
> occurrence of the referenced time. Thus, TZID=America/
31+
> New_York:20071104T013000 indicates November 4, 2007 at 1:30 A.M.
32+
> EDT (UTC-04:00).
33+
34+
Therefore in this example, a recurring 1:30 A.M. event should happen at
35+
the first occurence of 1:30 AM, immediately before the clocks are set back.
36+
"""
37+
test "should handle timezones at the fall DST boundary for a 1:30 AM event" do
38+
time = Timex.to_datetime({{2018, 11, 2}, {5, 0, 0}}, "America/Los_Angeles")
39+
40+
result =
41+
RR.take(
42+
time,
43+
%{freq: :daily, by_hour: 1, by_minute: 30, by_second: 0},
44+
5
45+
)
46+
47+
assert result ==
48+
date_tz_expand(
49+
[{{2018, 11, 2}, {5, 0, 0}}, {{2018, 11, 3..6}, {1, 30, 0}}],
50+
"America/Los_Angeles"
51+
)
52+
end
53+
54+
test "should handle timezones at the spring DST boundary" do
55+
time = Timex.to_datetime({{2019, 3, 8}, {5, 0, 0}}, "America/Los_Angeles")
56+
57+
result =
58+
RR.take(
59+
time,
60+
%{freq: :daily, by_hour: 3, by_minute: 0, by_second: 0},
61+
5
62+
)
63+
64+
assert result ==
65+
date_tz_expand(
66+
[{{2019, 3, 8}, {5, 0, 0}}, {{2019, 3, 9..12}, {3, 0, 0}}],
67+
"America/Los_Angeles"
68+
)
69+
end
70+
71+
@doc """
72+
From RFC 5545:
73+
74+
> If the local time described does not occur (when changing from standard
75+
> to daylight time), the DATE-TIME value is interpreted using the UTC
76+
> offset before the gap in local times. Thus,
77+
> TZID=America/New_York:20070311T023000 indicates March 11, 2007 at
78+
> 3:30 A.M. EDT (UTC-04:00), one hour after 1:30 A.M. EST (UTC-05:00).
79+
80+
Therefore in this example, a recurring 2:30 A.M. event should happen at
81+
3:30 AM immediately following the DST gap.
82+
"""
83+
test "should handle timezones at the spring DST boundary for a 2:30 AM event" do
84+
time = Timex.to_datetime({{2019, 3, 8}, {5, 0, 0}}, "America/New_York")
85+
86+
result =
87+
RR.take(
88+
time,
89+
%{freq: :daily, by_hour: 2, by_minute: 30, by_second: 0},
90+
5
91+
)
92+
93+
assert result ==
94+
date_tz_expand(
95+
[
96+
{{2019, 3, 8}, {5, 0, 0}},
97+
{{2019, 3, 9}, {2, 30, 0}},
98+
{{2019, 3, 10}, {3, 30, 0}},
99+
{{2019, 3, 11..12}, {2, 30, 0}}
100+
],
101+
"America/New_York"
102+
)
103+
end
104+
24105
@doc """
25106
Every other week - forever
26107

0 commit comments

Comments
 (0)