tzinfo 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of tzinfo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.yardopts +6 -0
- data/{CHANGES → CHANGES.md} +121 -50
- data/{README → README.md} +48 -34
- data/Rakefile +45 -22
- data/lib/tzinfo.rb +7 -2
- data/lib/tzinfo/country.rb +23 -1
- data/lib/tzinfo/country_index_definition.rb +6 -1
- data/lib/tzinfo/country_timezone.rb +9 -1
- data/lib/tzinfo/data_source.rb +26 -5
- data/lib/tzinfo/data_timezone.rb +30 -2
- data/lib/tzinfo/data_timezone_info.rb +26 -0
- data/lib/tzinfo/info_timezone.rb +3 -1
- data/lib/tzinfo/linked_timezone.rb +30 -1
- data/lib/tzinfo/offset_rationals.rb +5 -3
- data/lib/tzinfo/ruby_core_support.rb +2 -0
- data/lib/tzinfo/ruby_country_info.rb +14 -0
- data/lib/tzinfo/ruby_data_source.rb +5 -0
- data/lib/tzinfo/time_or_datetime.rb +16 -1
- data/lib/tzinfo/timezone.rb +107 -5
- data/lib/tzinfo/timezone_definition.rb +5 -1
- data/lib/tzinfo/timezone_index_definition.rb +7 -1
- data/lib/tzinfo/{timezone_offset_info.rb → timezone_offset.rb} +12 -10
- data/lib/tzinfo/timezone_period.rb +19 -15
- data/lib/tzinfo/timezone_proxy.rb +5 -1
- data/lib/tzinfo/timezone_transition.rb +136 -0
- data/lib/tzinfo/{timezone_transition_info.rb → timezone_transition_definition.rb} +21 -57
- data/lib/tzinfo/transition_data_timezone_info.rb +81 -8
- data/lib/tzinfo/zoneinfo_country_info.rb +7 -0
- data/lib/tzinfo/zoneinfo_data_source.rb +104 -57
- data/lib/tzinfo/zoneinfo_timezone_info.rb +18 -10
- data/test/tc_country.rb +39 -1
- data/test/tc_data_timezone.rb +28 -5
- data/test/tc_linked_timezone.rb +24 -3
- data/test/tc_ruby_data_source.rb +22 -2
- data/test/tc_time_or_datetime.rb +3 -3
- data/test/tc_timezone.rb +364 -117
- data/test/tc_timezone_london.rb +25 -0
- data/test/tc_timezone_melbourne.rb +24 -0
- data/test/tc_timezone_new_york.rb +24 -0
- data/test/{tc_timezone_offset_info.rb → tc_timezone_offset.rb} +27 -27
- data/test/tc_timezone_period.rb +113 -90
- data/test/tc_timezone_transition.rb +374 -0
- data/test/tc_timezone_transition_definition.rb +306 -0
- data/test/tc_transition_data_timezone_info.rb +143 -43
- data/test/tc_zoneinfo_data_source.rb +69 -5
- data/test/tc_zoneinfo_timezone_info.rb +63 -20
- data/test/test_utils.rb +27 -7
- data/tzinfo.gemspec +21 -0
- metadata +61 -38
- metadata.gz.sig +3 -0
- data/test/tc_timezone_transition_info.rb +0 -471
- data/test/zoneinfo/UTC +0 -0
- data/test/zoneinfo/localtime +0 -0
data/test/tc_timezone_london.rb
CHANGED
@@ -70,6 +70,18 @@ class TCTimezoneLondon < Test::Unit::TestCase
|
|
70
70
|
assert_equal(0, tz.period_for_local(DateTime.new(2004,10,31,1,59,59), false).utc_total_offset)
|
71
71
|
assert_equal(3600, tz.period_for_local(DateTime.new(2004,10,31,1,0,0), true).utc_total_offset)
|
72
72
|
assert_equal(0, tz.period_for_local(DateTime.new(2004,10,31,1,0,0), false).utc_total_offset)
|
73
|
+
|
74
|
+
transitions = tz.transitions_up_to(DateTime.new(2005,1,1,0,0,0), DateTime.new(2004,1,1,0,0,0))
|
75
|
+
assert_equal(2, transitions.length)
|
76
|
+
assert_equal(TimeOrDateTime.new(DateTime.new(2004,3,28,1,0,0)), transitions[0].at)
|
77
|
+
assert_equal(TimezoneOffset.new(0, 0, :GMT), transitions[0].previous_offset)
|
78
|
+
assert_equal(TimezoneOffset.new(0, 3600, :BST), transitions[0].offset)
|
79
|
+
assert_equal(TimeOrDateTime.new(DateTime.new(2004,10,31,1,0,0)), transitions[1].at)
|
80
|
+
assert_equal(TimezoneOffset.new(0, 3600, :BST), transitions[1].previous_offset)
|
81
|
+
assert_equal(TimezoneOffset.new(0, 0, :GMT), transitions[1].offset)
|
82
|
+
|
83
|
+
offsets = tz.offsets_up_to(DateTime.new(2005,1,1,0,0,0), DateTime.new(2004,1,1,0,0,0))
|
84
|
+
assert_array_same_items([TimezoneOffset.new(0, 0, :GMT), TimezoneOffset.new(0, 3600, :BST)], offsets)
|
73
85
|
end
|
74
86
|
|
75
87
|
def test_1961
|
@@ -122,6 +134,19 @@ class TCTimezoneLondon < Test::Unit::TestCase
|
|
122
134
|
assert_equal(0, tz.period_for_local(DateTime.new(1961,10,29,2,59,59), false).utc_total_offset)
|
123
135
|
assert_equal(3600, tz.period_for_local(DateTime.new(1961,10,29,2,0,0), true).utc_total_offset)
|
124
136
|
assert_equal(0, tz.period_for_local(DateTime.new(1961,10,29,2,0,0), false).utc_total_offset)
|
137
|
+
|
138
|
+
|
139
|
+
transitions = tz.transitions_up_to(DateTime.new(1962,1,1,0,0,0), DateTime.new(1961,1,1,0,0,0))
|
140
|
+
assert_equal(2, transitions.length)
|
141
|
+
assert_equal(TimeOrDateTime.new(DateTime.new(1961,3,26,2,0,0)), transitions[0].at)
|
142
|
+
assert_equal(TimezoneOffset.new(0, 0, :GMT), transitions[0].previous_offset)
|
143
|
+
assert_equal(TimezoneOffset.new(0, 3600, :BST), transitions[0].offset)
|
144
|
+
assert_equal(TimeOrDateTime.new(DateTime.new(1961,10,29,2,0,0)), transitions[1].at)
|
145
|
+
assert_equal(TimezoneOffset.new(0, 3600, :BST), transitions[1].previous_offset)
|
146
|
+
assert_equal(TimezoneOffset.new(0, 0, :GMT), transitions[1].offset)
|
147
|
+
|
148
|
+
offsets = tz.offsets_up_to(DateTime.new(1962,1,1,0,0,0), DateTime.new(1961,1,1,0,0,0))
|
149
|
+
assert_array_same_items([TimezoneOffset.new(0, 0, :GMT), TimezoneOffset.new(0, 3600, :BST)], offsets)
|
125
150
|
end
|
126
151
|
end
|
127
152
|
|
@@ -70,6 +70,18 @@ class TCTimezoneMelbourne < Test::Unit::TestCase
|
|
70
70
|
assert_equal(36000, tz.period_for_local(DateTime.new(2004,3,28,2,0,0), false).utc_total_offset)
|
71
71
|
assert_equal(36000, tz.period_for_local(DateTime.new(2004,10,31,1,59,59)).utc_total_offset)
|
72
72
|
assert_equal(39600, tz.period_for_local(DateTime.new(2004,10,31,3,0,0)).utc_total_offset)
|
73
|
+
|
74
|
+
transitions = tz.transitions_up_to(DateTime.new(2005,1,1,0,0,0), DateTime.new(2004,1,1,0,0,0))
|
75
|
+
assert_equal(2, transitions.length)
|
76
|
+
assert_equal(TimeOrDateTime.new(DateTime.new(2004,3,27,16,0,0)), transitions[0].at)
|
77
|
+
assert_equal(TimezoneOffset.new(36000, 3600, :EST), transitions[0].previous_offset)
|
78
|
+
assert_equal(TimezoneOffset.new(36000, 0, :EST), transitions[0].offset)
|
79
|
+
assert_equal(TimeOrDateTime.new(DateTime.new(2004,10,30,16,0,0)), transitions[1].at)
|
80
|
+
assert_equal(TimezoneOffset.new(36000, 0, :EST), transitions[1].previous_offset)
|
81
|
+
assert_equal(TimezoneOffset.new(36000, 3600, :EST), transitions[1].offset)
|
82
|
+
|
83
|
+
offsets = tz.offsets_up_to(DateTime.new(2005,1,1,0,0,0), DateTime.new(2004,1,1,0,0,0))
|
84
|
+
assert_array_same_items([TimezoneOffset.new(36000, 0, :EST), TimezoneOffset.new(36000, 3600, :EST)], offsets)
|
73
85
|
end
|
74
86
|
|
75
87
|
def test_1942
|
@@ -122,6 +134,18 @@ class TCTimezoneMelbourne < Test::Unit::TestCase
|
|
122
134
|
assert_equal(36000, tz.period_for_local(DateTime.new(1942,3,29,1,0,0), false).utc_total_offset)
|
123
135
|
assert_equal(36000, tz.period_for_local(DateTime.new(1942,9,27,1,59,59)).utc_total_offset)
|
124
136
|
assert_equal(39600, tz.period_for_local(DateTime.new(1942,9,27,3,0,0)).utc_total_offset)
|
137
|
+
|
138
|
+
transitions = tz.transitions_up_to(DateTime.new(1943,1,1,0,0,0), DateTime.new(1942,1,1,0,0,0))
|
139
|
+
assert_equal(2, transitions.length)
|
140
|
+
assert_equal(TimeOrDateTime.new(DateTime.new(1942,3,28,15,0,0)), transitions[0].at)
|
141
|
+
assert_equal(TimezoneOffset.new(36000, 3600, :EST), transitions[0].previous_offset)
|
142
|
+
assert_equal(TimezoneOffset.new(36000, 0, :EST), transitions[0].offset)
|
143
|
+
assert_equal(TimeOrDateTime.new(DateTime.new(1942,9,26,16,0,0)), transitions[1].at)
|
144
|
+
assert_equal(TimezoneOffset.new(36000, 0, :EST), transitions[1].previous_offset)
|
145
|
+
assert_equal(TimezoneOffset.new(36000, 3600, :EST), transitions[1].offset)
|
146
|
+
|
147
|
+
offsets = tz.offsets_up_to(DateTime.new(1943,1,1,0,0,0), DateTime.new(1942,1,1,0,0,0))
|
148
|
+
assert_array_same_items([TimezoneOffset.new(36000, 0, :EST), TimezoneOffset.new(36000, 3600, :EST)], offsets)
|
125
149
|
end
|
126
150
|
end
|
127
151
|
|
@@ -70,6 +70,18 @@ class TCTimezoneNewYork < Test::Unit::TestCase
|
|
70
70
|
assert_equal(-18000, tz.period_for_local(DateTime.new(2004,10,31,1,59,59), false).utc_total_offset)
|
71
71
|
assert_equal(-14400, tz.period_for_local(DateTime.new(2004,10,31,1,0,0), true).utc_total_offset)
|
72
72
|
assert_equal(-18000, tz.period_for_local(DateTime.new(2004,10,31,1,0,0), false).utc_total_offset)
|
73
|
+
|
74
|
+
transitions = tz.transitions_up_to(DateTime.new(2005,1,1,0,0,0), DateTime.new(2004,1,1,0,0,0))
|
75
|
+
assert_equal(2, transitions.length)
|
76
|
+
assert_equal(TimeOrDateTime.new(DateTime.new(2004,4,4,7,0,0)), transitions[0].at)
|
77
|
+
assert_equal(TimezoneOffset.new(-18000, 0, :EST), transitions[0].previous_offset)
|
78
|
+
assert_equal(TimezoneOffset.new(-18000, 3600, :EDT), transitions[0].offset)
|
79
|
+
assert_equal(TimeOrDateTime.new(DateTime.new(2004,10,31,6,0,0)), transitions[1].at)
|
80
|
+
assert_equal(TimezoneOffset.new(-18000, 3600, :EDT), transitions[1].previous_offset)
|
81
|
+
assert_equal(TimezoneOffset.new(-18000, 0, :EST), transitions[1].offset)
|
82
|
+
|
83
|
+
offsets = tz.offsets_up_to(DateTime.new(2005,1,1,0,0,0), DateTime.new(2004,1,1,0,0,0))
|
84
|
+
assert_array_same_items([TimezoneOffset.new(-18000, 0, :EST), TimezoneOffset.new(-18000, 3600, :EDT)], offsets)
|
73
85
|
end
|
74
86
|
|
75
87
|
def test_1957
|
@@ -122,6 +134,18 @@ class TCTimezoneNewYork < Test::Unit::TestCase
|
|
122
134
|
assert_equal(-18000, tz.period_for_local(DateTime.new(1957,10,27,1,59,59), false).utc_total_offset)
|
123
135
|
assert_equal(-14400, tz.period_for_local(DateTime.new(1957,10,27,1,0,0), true).utc_total_offset)
|
124
136
|
assert_equal(-18000, tz.period_for_local(DateTime.new(1957,10,27,1,0,0), false).utc_total_offset)
|
137
|
+
|
138
|
+
transitions = tz.transitions_up_to(DateTime.new(1958,1,1,0,0,0), DateTime.new(1957,1,1,0,0,0))
|
139
|
+
assert_equal(2, transitions.length)
|
140
|
+
assert_equal(TimeOrDateTime.new(DateTime.new(1957,4,28,7,0,0)), transitions[0].at)
|
141
|
+
assert_equal(TimezoneOffset.new(-18000, 0, :EST), transitions[0].previous_offset)
|
142
|
+
assert_equal(TimezoneOffset.new(-18000, 3600, :EDT), transitions[0].offset)
|
143
|
+
assert_equal(TimeOrDateTime.new(DateTime.new(1957,10,27,6,0,0)), transitions[1].at)
|
144
|
+
assert_equal(TimezoneOffset.new(-18000, 3600, :EDT), transitions[1].previous_offset)
|
145
|
+
assert_equal(TimezoneOffset.new(-18000, 0, :EST), transitions[1].offset)
|
146
|
+
|
147
|
+
offsets = tz.offsets_up_to(DateTime.new(1958,1,1,0,0,0), DateTime.new(1957,1,1,0,0,0))
|
148
|
+
assert_array_same_items([TimezoneOffset.new(-18000, 0, :EST), TimezoneOffset.new(-18000, 3600, :EDT)], offsets)
|
125
149
|
end
|
126
150
|
end
|
127
151
|
|
@@ -24,51 +24,51 @@ require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
|
|
24
24
|
|
25
25
|
include TZInfo
|
26
26
|
|
27
|
-
class
|
27
|
+
class TCTimezoneOffset < Test::Unit::TestCase
|
28
28
|
|
29
29
|
def test_utc_offset
|
30
|
-
o1 =
|
31
|
-
o2 =
|
30
|
+
o1 = TimezoneOffset.new(18000, 0, :TEST)
|
31
|
+
o2 = TimezoneOffset.new(-3600, 3600, :TEST2)
|
32
32
|
|
33
33
|
assert_equal(18000, o1.utc_offset)
|
34
34
|
assert_equal(-3600, o2.utc_offset)
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_std_offset
|
38
|
-
o1 =
|
39
|
-
o2 =
|
38
|
+
o1 = TimezoneOffset.new(18000, 0, :TEST)
|
39
|
+
o2 = TimezoneOffset.new(-3600, 3600, :TEST2)
|
40
40
|
|
41
41
|
assert_equal(0, o1.std_offset)
|
42
42
|
assert_equal(3600, o2.std_offset)
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_utc_total_offset
|
46
|
-
o1 =
|
47
|
-
o2 =
|
46
|
+
o1 = TimezoneOffset.new(18000, 0, :TEST)
|
47
|
+
o2 = TimezoneOffset.new(-3600, 3600, :TEST2)
|
48
48
|
|
49
49
|
assert_equal(18000, o1.utc_total_offset)
|
50
50
|
assert_equal(0, o2.utc_total_offset)
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_abbreviation
|
54
|
-
o1 =
|
55
|
-
o2 =
|
54
|
+
o1 = TimezoneOffset.new(18000, 0, :TEST)
|
55
|
+
o2 = TimezoneOffset.new(-3600, 3600, :TEST2)
|
56
56
|
|
57
57
|
assert_equal(:TEST, o1.abbreviation)
|
58
58
|
assert_equal(:TEST2, o2.abbreviation)
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_dst
|
62
|
-
o1 =
|
63
|
-
o2 =
|
62
|
+
o1 = TimezoneOffset.new(18000, 0, :TEST)
|
63
|
+
o2 = TimezoneOffset.new(-3600, 3600, :TEST2)
|
64
64
|
|
65
65
|
assert_equal(false, o1.dst?)
|
66
66
|
assert_equal(true, o2.dst?)
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_to_local
|
70
|
-
o1 =
|
71
|
-
o2 =
|
70
|
+
o1 = TimezoneOffset.new(18000, 0, :TEST)
|
71
|
+
o2 = TimezoneOffset.new(-3600, 3600, :TEST2)
|
72
72
|
|
73
73
|
assert_equal(1148949080, o1.to_local(1148931080))
|
74
74
|
assert_equal(Time.utc(2006, 5, 30, 0, 31, 20), o1.to_local(Time.utc(2006, 5, 29, 19, 31, 20)))
|
@@ -88,8 +88,8 @@ class TCTimezoneOffsetInfo < Test::Unit::TestCase
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def test_to_utc
|
91
|
-
o1 =
|
92
|
-
o2 =
|
91
|
+
o1 = TimezoneOffset.new(18000, 0, :TEST)
|
92
|
+
o2 = TimezoneOffset.new(-3600, 3600, :TEST2)
|
93
93
|
|
94
94
|
assert_equal(1148913080, o1.to_utc(1148931080))
|
95
95
|
assert_equal(Time.utc(2006, 5, 29, 14, 31, 20), o1.to_utc(Time.utc(2006, 5, 29, 19, 31, 20)))
|
@@ -109,11 +109,11 @@ class TCTimezoneOffsetInfo < Test::Unit::TestCase
|
|
109
109
|
end
|
110
110
|
|
111
111
|
def test_equality
|
112
|
-
o1 =
|
113
|
-
o2 =
|
114
|
-
o3 =
|
115
|
-
o4 =
|
116
|
-
o5 =
|
112
|
+
o1 = TimezoneOffset.new(18000, 0, :TEST)
|
113
|
+
o2 = TimezoneOffset.new(18000, 0, :TEST)
|
114
|
+
o3 = TimezoneOffset.new(18001, 0, :TEST)
|
115
|
+
o4 = TimezoneOffset.new(18000, 1, :TEST)
|
116
|
+
o5 = TimezoneOffset.new(18000, 0, :TEST2)
|
117
117
|
|
118
118
|
assert_equal(true, o1 == o1)
|
119
119
|
assert_equal(true, o1 == o2)
|
@@ -124,11 +124,11 @@ class TCTimezoneOffsetInfo < Test::Unit::TestCase
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def test_eql
|
127
|
-
o1 =
|
128
|
-
o2 =
|
129
|
-
o3 =
|
130
|
-
o4 =
|
131
|
-
o5 =
|
127
|
+
o1 = TimezoneOffset.new(18000, 0, :TEST)
|
128
|
+
o2 = TimezoneOffset.new(18000, 0, :TEST)
|
129
|
+
o3 = TimezoneOffset.new(18001, 0, :TEST)
|
130
|
+
o4 = TimezoneOffset.new(18000, 1, :TEST)
|
131
|
+
o5 = TimezoneOffset.new(18000, 0, :TEST2)
|
132
132
|
|
133
133
|
assert_equal(true, o1.eql?(o1))
|
134
134
|
assert_equal(true, o1.eql?(o2))
|
@@ -139,8 +139,8 @@ class TCTimezoneOffsetInfo < Test::Unit::TestCase
|
|
139
139
|
end
|
140
140
|
|
141
141
|
def test_hash
|
142
|
-
o1 =
|
143
|
-
o2 =
|
142
|
+
o1 = TimezoneOffset.new(18000, 0, :TEST)
|
143
|
+
o2 = TimezoneOffset.new(-3600, 3600, :TEST2)
|
144
144
|
|
145
145
|
assert_equal(18000.hash ^ 0.hash ^ :TEST.hash, o1.hash)
|
146
146
|
assert_equal(-3600.hash ^ 3600.hash ^ :TEST2.hash, o2.hash)
|
data/test/tc_timezone_period.rb
CHANGED
@@ -26,14 +26,28 @@ include TZInfo
|
|
26
26
|
|
27
27
|
class TCTimezonePeriod < Test::Unit::TestCase
|
28
28
|
|
29
|
+
class TestTimezoneTransition < TimezoneTransition
|
30
|
+
def initialize(offset, previous_offset, at)
|
31
|
+
super(offset, previous_offset)
|
32
|
+
@at = TimeOrDateTime.wrap(at)
|
33
|
+
end
|
34
|
+
|
35
|
+
def at
|
36
|
+
@at
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
29
40
|
def test_initialize_start_end
|
30
|
-
std =
|
31
|
-
dst =
|
32
|
-
start_t =
|
33
|
-
end_t =
|
41
|
+
std = TimezoneOffset.new(-7200, 0, :TEST)
|
42
|
+
dst = TimezoneOffset.new(-7200, 3600, :TEST)
|
43
|
+
start_t = TestTimezoneTransition.new(dst, std, 1136073600)
|
44
|
+
end_t = TestTimezoneTransition.new(std, dst, 1136160000)
|
34
45
|
|
35
46
|
p = TimezonePeriod.new(start_t, end_t)
|
36
47
|
|
48
|
+
assert_same(start_t, p.start_transition)
|
49
|
+
assert_same(end_t, p.end_transition)
|
50
|
+
assert_same(dst, p.offset)
|
37
51
|
assert_equal(DateTime.new(2006,1,1,0,0,0), p.utc_start)
|
38
52
|
assert_equal(Time.utc(2006,1,1,0,0,0), p.utc_start_time)
|
39
53
|
assert_equal(DateTime.new(2006,1,2,0,0,0), p.utc_end)
|
@@ -51,22 +65,25 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
51
65
|
end
|
52
66
|
|
53
67
|
def test_initialize_start_end_offset
|
54
|
-
std =
|
55
|
-
dst =
|
56
|
-
special =
|
57
|
-
start_t =
|
58
|
-
end_t =
|
68
|
+
std = TimezoneOffset.new(-7200, 0, :TEST)
|
69
|
+
dst = TimezoneOffset.new(-7200, 3600, :TEST)
|
70
|
+
special = TimezoneOffset.new(0, 0, :SPECIAL)
|
71
|
+
start_t = TestTimezoneTransition.new(dst, std, 1136073600)
|
72
|
+
end_t = TestTimezoneTransition.new(std, dst, 1136160000)
|
59
73
|
|
60
74
|
assert_raises(ArgumentError) { TimezonePeriod.new(start_t, end_t, special) }
|
61
75
|
end
|
62
76
|
|
63
77
|
def test_initialize_start
|
64
|
-
std =
|
65
|
-
dst =
|
66
|
-
start_t =
|
78
|
+
std = TimezoneOffset.new(-7200, 0, :TEST)
|
79
|
+
dst = TimezoneOffset.new(-7200, 3600, :TEST)
|
80
|
+
start_t = TestTimezoneTransition.new(dst, std, 1136073600)
|
67
81
|
|
68
82
|
p = TimezonePeriod.new(start_t, nil)
|
69
83
|
|
84
|
+
assert_same(start_t, p.start_transition)
|
85
|
+
assert_nil(p.end_transition)
|
86
|
+
assert_same(dst, p.offset)
|
70
87
|
assert_equal(DateTime.new(2006,1,1,0,0,0), p.utc_start)
|
71
88
|
assert_equal(Time.utc(2006,1,1,0,0,0), p.utc_start_time)
|
72
89
|
assert_nil(p.utc_end)
|
@@ -84,21 +101,24 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
84
101
|
end
|
85
102
|
|
86
103
|
def test_initialize_start_offset
|
87
|
-
std =
|
88
|
-
dst =
|
89
|
-
special =
|
90
|
-
start_t =
|
104
|
+
std = TimezoneOffset.new(-7200, 0, :TEST)
|
105
|
+
dst = TimezoneOffset.new(-7200, 3600, :TEST)
|
106
|
+
special = TimezoneOffset.new(0, 0, :SPECIAL)
|
107
|
+
start_t = TestTimezoneTransition.new(dst, std, 1136073600)
|
91
108
|
|
92
109
|
assert_raises(ArgumentError) { TimezonePeriod.new(start_t, nil, special) }
|
93
110
|
end
|
94
111
|
|
95
112
|
def test_initialize_end
|
96
|
-
std =
|
97
|
-
dst =
|
98
|
-
end_t =
|
113
|
+
std = TimezoneOffset.new(-7200, 0, :TEST)
|
114
|
+
dst = TimezoneOffset.new(-7200, 3600, :TEST)
|
115
|
+
end_t = TestTimezoneTransition.new(std, dst, 1136160000)
|
99
116
|
|
100
117
|
p = TimezonePeriod.new(nil, end_t)
|
101
118
|
|
119
|
+
assert_nil(p.start_transition)
|
120
|
+
assert_same(end_t, p.end_transition)
|
121
|
+
assert_same(dst, p.offset)
|
102
122
|
assert_nil(p.utc_start)
|
103
123
|
assert_nil(p.utc_start_time)
|
104
124
|
assert_equal(DateTime.new(2006,1,2,0,0,0), p.utc_end)
|
@@ -116,10 +136,10 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
116
136
|
end
|
117
137
|
|
118
138
|
def test_initialize_end_offset
|
119
|
-
std =
|
120
|
-
dst =
|
121
|
-
special =
|
122
|
-
end_t =
|
139
|
+
std = TimezoneOffset.new(-7200, 0, :TEST)
|
140
|
+
dst = TimezoneOffset.new(-7200, 3600, :TEST)
|
141
|
+
special = TimezoneOffset.new(0, 0, :SPECIAL)
|
142
|
+
end_t = TestTimezoneTransition.new(std, dst, 1136160000)
|
123
143
|
|
124
144
|
assert_raises(ArgumentError) { TimezonePeriod.new(nil, end_t, special) }
|
125
145
|
end
|
@@ -129,10 +149,13 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
129
149
|
end
|
130
150
|
|
131
151
|
def test_initialize_offset
|
132
|
-
special =
|
152
|
+
special = TimezoneOffset.new(0, 0, :SPECIAL)
|
133
153
|
|
134
154
|
p = TimezonePeriod.new(nil, nil, special)
|
135
155
|
|
156
|
+
assert_nil(p.start_transition)
|
157
|
+
assert_nil(p.end_transition)
|
158
|
+
assert_same(special, p.offset)
|
136
159
|
assert_nil(p.utc_start)
|
137
160
|
assert_nil(p.utc_start_time)
|
138
161
|
assert_nil(p.utc_end)
|
@@ -150,11 +173,11 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
150
173
|
end
|
151
174
|
|
152
175
|
def test_dst
|
153
|
-
p1 = TimezonePeriod.new(nil, nil,
|
154
|
-
p2 = TimezonePeriod.new(nil, nil,
|
155
|
-
p3 = TimezonePeriod.new(nil, nil,
|
156
|
-
p4 = TimezonePeriod.new(nil, nil,
|
157
|
-
p5 = TimezonePeriod.new(nil, nil,
|
176
|
+
p1 = TimezonePeriod.new(nil, nil, TimezoneOffset.new(-14400, 3600, :TEST))
|
177
|
+
p2 = TimezonePeriod.new(nil, nil, TimezoneOffset.new(-14400, 0, :TEST))
|
178
|
+
p3 = TimezonePeriod.new(nil, nil, TimezoneOffset.new(-14400, -3600, :TEST))
|
179
|
+
p4 = TimezonePeriod.new(nil, nil, TimezoneOffset.new(-14400, 7200, :TEST))
|
180
|
+
p5 = TimezonePeriod.new(nil, nil, TimezoneOffset.new(-14400, -7200, :TEST))
|
158
181
|
|
159
182
|
assert_equal(true, p1.dst?)
|
160
183
|
assert_equal(false, p2.dst?)
|
@@ -164,11 +187,11 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
164
187
|
end
|
165
188
|
|
166
189
|
def test_valid_for_utc
|
167
|
-
offset =
|
168
|
-
t1 =
|
169
|
-
t2 =
|
170
|
-
t3 =
|
171
|
-
t4 =
|
190
|
+
offset = TimezoneOffset.new(-7200, 3600, :TEST)
|
191
|
+
t1 = TestTimezoneTransition.new(offset, offset, 1104541261)
|
192
|
+
t2 = TestTimezoneTransition.new(offset, offset, 1107309722)
|
193
|
+
t3 = TestTimezoneTransition.new(offset, offset, DateTime.new(1960, 1, 1, 1, 1, 1))
|
194
|
+
t4 = TestTimezoneTransition.new(offset, offset, DateTime.new(1960, 2, 2, 2, 2, 2))
|
172
195
|
|
173
196
|
p1 = TimezonePeriod.new(t1, t2)
|
174
197
|
p2 = TimezonePeriod.new(nil, t2)
|
@@ -217,11 +240,11 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
217
240
|
end
|
218
241
|
|
219
242
|
def test_utc_after_start
|
220
|
-
offset =
|
221
|
-
t1 =
|
222
|
-
t2 =
|
223
|
-
t3 =
|
224
|
-
t4 =
|
243
|
+
offset = TimezoneOffset.new(-7200, 3600, :TEST)
|
244
|
+
t1 = TestTimezoneTransition.new(offset, offset, 1104541261)
|
245
|
+
t2 = TestTimezoneTransition.new(offset, offset, 1107309722)
|
246
|
+
t3 = TestTimezoneTransition.new(offset, offset, DateTime.new(1945, 1, 1, 1, 1, 1))
|
247
|
+
t4 = TestTimezoneTransition.new(offset, offset, DateTime.new(1945, 2, 2, 2, 2, 2))
|
225
248
|
|
226
249
|
p1 = TimezonePeriod.new(t1, t2)
|
227
250
|
p2 = TimezonePeriod.new(nil, t2)
|
@@ -242,11 +265,11 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
242
265
|
end
|
243
266
|
|
244
267
|
def test_utc_before_end
|
245
|
-
offset =
|
246
|
-
t1 =
|
247
|
-
t2 =
|
248
|
-
t3 =
|
249
|
-
t4 =
|
268
|
+
offset = TimezoneOffset.new(-7200, 3600, :TEST)
|
269
|
+
t1 = TestTimezoneTransition.new(offset, offset, 1104541261)
|
270
|
+
t2 = TestTimezoneTransition.new(offset, offset, 1107309722)
|
271
|
+
t3 = TestTimezoneTransition.new(offset, offset, DateTime.new(1945, 1, 1, 1, 1, 1))
|
272
|
+
t4 = TestTimezoneTransition.new(offset, offset, DateTime.new(1945, 2, 2, 2, 2, 2))
|
250
273
|
|
251
274
|
p1 = TimezonePeriod.new(t1, t2)
|
252
275
|
p2 = TimezonePeriod.new(t1, nil)
|
@@ -267,12 +290,12 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
267
290
|
end
|
268
291
|
|
269
292
|
def test_valid_for_local
|
270
|
-
offset =
|
271
|
-
t1 =
|
272
|
-
t2 =
|
273
|
-
t3 =
|
274
|
-
t4 =
|
275
|
-
t5 =
|
293
|
+
offset = TimezoneOffset.new(-7200, 3600, :TEST)
|
294
|
+
t1 = TestTimezoneTransition.new(offset, offset, 1104544861)
|
295
|
+
t2 = TestTimezoneTransition.new(offset, offset, 1107313322)
|
296
|
+
t3 = TestTimezoneTransition.new(offset, offset, 1104544861)
|
297
|
+
t4 = TestTimezoneTransition.new(offset, offset, DateTime.new(1960, 1, 1, 1, 1, 1))
|
298
|
+
t5 = TestTimezoneTransition.new(offset, offset, DateTime.new(1960, 2, 2, 2, 2, 2))
|
276
299
|
|
277
300
|
p1 = TimezonePeriod.new(t1, t2)
|
278
301
|
p2 = TimezonePeriod.new(nil, t2)
|
@@ -321,11 +344,11 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
321
344
|
end
|
322
345
|
|
323
346
|
def test_local_after_start
|
324
|
-
offset =
|
325
|
-
t1 =
|
326
|
-
t2 =
|
327
|
-
t3 =
|
328
|
-
t4 =
|
347
|
+
offset = TimezoneOffset.new(-7200, 3600, :TEST)
|
348
|
+
t1 = TestTimezoneTransition.new(offset, offset, 1104544861)
|
349
|
+
t2 = TestTimezoneTransition.new(offset, offset, 1107313322)
|
350
|
+
t3 = TestTimezoneTransition.new(offset, offset, DateTime.new(1945, 1, 1, 1, 1, 1))
|
351
|
+
t4 = TestTimezoneTransition.new(offset, offset, DateTime.new(1945, 2, 2, 2, 2, 2))
|
329
352
|
|
330
353
|
p1 = TimezonePeriod.new(t1, t2)
|
331
354
|
p2 = TimezonePeriod.new(nil, t2)
|
@@ -346,11 +369,11 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
346
369
|
end
|
347
370
|
|
348
371
|
def test_local_before_end
|
349
|
-
offset =
|
350
|
-
t1 =
|
351
|
-
t2 =
|
352
|
-
t3 =
|
353
|
-
t4 =
|
372
|
+
offset = TimezoneOffset.new(-7200, 3600, :TEST)
|
373
|
+
t1 = TestTimezoneTransition.new(offset, offset, 1104544861)
|
374
|
+
t2 = TestTimezoneTransition.new(offset, offset, 1107313322)
|
375
|
+
t3 = TestTimezoneTransition.new(offset, offset, DateTime.new(1945, 1, 1, 1, 1, 1))
|
376
|
+
t4 = TestTimezoneTransition.new(offset, offset, DateTime.new(1945, 2, 2, 2, 2, 2))
|
354
377
|
|
355
378
|
p1 = TimezonePeriod.new(t1, t2)
|
356
379
|
p2 = TimezonePeriod.new(t1, nil)
|
@@ -371,9 +394,9 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
371
394
|
end
|
372
395
|
|
373
396
|
def test_to_local
|
374
|
-
p1 = TimezonePeriod.new(nil, nil,
|
375
|
-
p2 = TimezonePeriod.new(nil, nil,
|
376
|
-
p3 = TimezonePeriod.new(nil, nil,
|
397
|
+
p1 = TimezonePeriod.new(nil, nil, TimezoneOffset.new(-14400, 3600, :TEST))
|
398
|
+
p2 = TimezonePeriod.new(nil, nil, TimezoneOffset.new(-14400, 0, :TEST))
|
399
|
+
p3 = TimezonePeriod.new(nil, nil, TimezoneOffset.new(7200, 3600, :TEST))
|
377
400
|
|
378
401
|
assert_equal(DateTime.new(2005,1,19,22,0,0), p1.to_local(DateTime.new(2005,1,20,1,0,0)))
|
379
402
|
assert_equal(DateTime.new(2005,1,19,22,0,0 + Rational(512,1000)), p1.to_local(DateTime.new(2005,1,20,1,0,0 + Rational(512,1000))))
|
@@ -383,9 +406,9 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
383
406
|
end
|
384
407
|
|
385
408
|
def test_to_utc
|
386
|
-
p1 = TimezonePeriod.new(nil, nil,
|
387
|
-
p2 = TimezonePeriod.new(nil, nil,
|
388
|
-
p3 = TimezonePeriod.new(nil, nil,
|
409
|
+
p1 = TimezonePeriod.new(nil, nil, TimezoneOffset.new(-14400, 3600, :TEST))
|
410
|
+
p2 = TimezonePeriod.new(nil, nil, TimezoneOffset.new(-14400, 0, :TEST))
|
411
|
+
p3 = TimezonePeriod.new(nil, nil, TimezoneOffset.new(7200, 3600, :TEST))
|
389
412
|
|
390
413
|
assert_equal(DateTime.new(2005,1,20,4,0,0), p1.to_utc(DateTime.new(2005,1,20,1,0,0)))
|
391
414
|
assert_equal(DateTime.new(2005,1,20,4,0,0 + Rational(571,1000)), p1.to_utc(DateTime.new(2005,1,20,1,0,0 + Rational(571,1000))))
|
@@ -395,9 +418,9 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
395
418
|
end
|
396
419
|
|
397
420
|
def test_time_boundary_start
|
398
|
-
o1 =
|
399
|
-
o2 =
|
400
|
-
t1 =
|
421
|
+
o1 = TimezoneOffset.new(-3600, 0, :TEST)
|
422
|
+
o2 = TimezoneOffset.new(-3600, 3600, :TEST)
|
423
|
+
t1 = TestTimezoneTransition.new(o1, o2, 0)
|
401
424
|
|
402
425
|
p1 = TimezonePeriod.new(t1, nil)
|
403
426
|
|
@@ -410,9 +433,9 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
410
433
|
end
|
411
434
|
|
412
435
|
def test_time_boundary_end
|
413
|
-
o1 =
|
414
|
-
o2 =
|
415
|
-
t1 =
|
436
|
+
o1 = TimezoneOffset.new(0, 3600, :TEST)
|
437
|
+
o2 = TimezoneOffset.new(0, 0, :TEST)
|
438
|
+
t1 = TestTimezoneTransition.new(o2, o1, 2147482800)
|
416
439
|
|
417
440
|
p1 = TimezonePeriod.new(nil, t1)
|
418
441
|
|
@@ -425,12 +448,12 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
425
448
|
end
|
426
449
|
|
427
450
|
def test_equality
|
428
|
-
o1 =
|
429
|
-
o2 =
|
430
|
-
t1 =
|
431
|
-
t2 =
|
432
|
-
t3 =
|
433
|
-
t4 =
|
451
|
+
o1 = TimezoneOffset.new(0, 3600, :TEST)
|
452
|
+
o2 = TimezoneOffset.new(0, 0, :TEST)
|
453
|
+
t1 = TestTimezoneTransition.new(o1, o2, 1149368400)
|
454
|
+
t2 = TestTimezoneTransition.new(o1, o2, DateTime.new(2006, 6, 3, 21, 0, 0))
|
455
|
+
t3 = TestTimezoneTransition.new(o1, o2, 1149454800)
|
456
|
+
t4 = TestTimezoneTransition.new(o1, o2, 1149541200)
|
434
457
|
|
435
458
|
p1 = TimezonePeriod.new(t1, t3)
|
436
459
|
p2 = TimezonePeriod.new(t1, t3)
|
@@ -476,12 +499,12 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
476
499
|
end
|
477
500
|
|
478
501
|
def test_eql
|
479
|
-
o1 =
|
480
|
-
o2 =
|
481
|
-
t1 =
|
482
|
-
t2 =
|
483
|
-
t3 =
|
484
|
-
t4 =
|
502
|
+
o1 = TimezoneOffset.new(0, 3600, :TEST)
|
503
|
+
o2 = TimezoneOffset.new(0, 0, :TEST)
|
504
|
+
t1 = TestTimezoneTransition.new(o1, o2, 1149368400)
|
505
|
+
t2 = TestTimezoneTransition.new(o1, o2, DateTime.new(2006, 6, 3, 21, 0, 0))
|
506
|
+
t3 = TestTimezoneTransition.new(o1, o2, 1149454800)
|
507
|
+
t4 = TestTimezoneTransition.new(o1, o2, 1149541200)
|
485
508
|
|
486
509
|
p1 = TimezonePeriod.new(t1, t3)
|
487
510
|
p2 = TimezonePeriod.new(t1, t3)
|
@@ -527,12 +550,12 @@ class TCTimezonePeriod < Test::Unit::TestCase
|
|
527
550
|
end
|
528
551
|
|
529
552
|
def test_hash
|
530
|
-
o1 =
|
531
|
-
o2 =
|
532
|
-
t1 =
|
533
|
-
t2 =
|
534
|
-
t3 =
|
535
|
-
t4 =
|
553
|
+
o1 = TimezoneOffset.new(0, 3600, :TEST)
|
554
|
+
o2 = TimezoneOffset.new(0, 0, :TEST)
|
555
|
+
t1 = TestTimezoneTransition.new(o1, o2, 1149368400)
|
556
|
+
t2 = TestTimezoneTransition.new(o1, o2, DateTime.new(2006, 6, 3, 21, 0, 0))
|
557
|
+
t3 = TestTimezoneTransition.new(o1, o2, 1149454800)
|
558
|
+
t4 = TestTimezoneTransition.new(o1, o2, 1149541200)
|
536
559
|
|
537
560
|
p1 = TimezonePeriod.new(t1, t3)
|
538
561
|
p2 = TimezonePeriod.new(t3, nil)
|