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.

Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.yardopts +6 -0
  5. data/{CHANGES → CHANGES.md} +121 -50
  6. data/{README → README.md} +48 -34
  7. data/Rakefile +45 -22
  8. data/lib/tzinfo.rb +7 -2
  9. data/lib/tzinfo/country.rb +23 -1
  10. data/lib/tzinfo/country_index_definition.rb +6 -1
  11. data/lib/tzinfo/country_timezone.rb +9 -1
  12. data/lib/tzinfo/data_source.rb +26 -5
  13. data/lib/tzinfo/data_timezone.rb +30 -2
  14. data/lib/tzinfo/data_timezone_info.rb +26 -0
  15. data/lib/tzinfo/info_timezone.rb +3 -1
  16. data/lib/tzinfo/linked_timezone.rb +30 -1
  17. data/lib/tzinfo/offset_rationals.rb +5 -3
  18. data/lib/tzinfo/ruby_core_support.rb +2 -0
  19. data/lib/tzinfo/ruby_country_info.rb +14 -0
  20. data/lib/tzinfo/ruby_data_source.rb +5 -0
  21. data/lib/tzinfo/time_or_datetime.rb +16 -1
  22. data/lib/tzinfo/timezone.rb +107 -5
  23. data/lib/tzinfo/timezone_definition.rb +5 -1
  24. data/lib/tzinfo/timezone_index_definition.rb +7 -1
  25. data/lib/tzinfo/{timezone_offset_info.rb → timezone_offset.rb} +12 -10
  26. data/lib/tzinfo/timezone_period.rb +19 -15
  27. data/lib/tzinfo/timezone_proxy.rb +5 -1
  28. data/lib/tzinfo/timezone_transition.rb +136 -0
  29. data/lib/tzinfo/{timezone_transition_info.rb → timezone_transition_definition.rb} +21 -57
  30. data/lib/tzinfo/transition_data_timezone_info.rb +81 -8
  31. data/lib/tzinfo/zoneinfo_country_info.rb +7 -0
  32. data/lib/tzinfo/zoneinfo_data_source.rb +104 -57
  33. data/lib/tzinfo/zoneinfo_timezone_info.rb +18 -10
  34. data/test/tc_country.rb +39 -1
  35. data/test/tc_data_timezone.rb +28 -5
  36. data/test/tc_linked_timezone.rb +24 -3
  37. data/test/tc_ruby_data_source.rb +22 -2
  38. data/test/tc_time_or_datetime.rb +3 -3
  39. data/test/tc_timezone.rb +364 -117
  40. data/test/tc_timezone_london.rb +25 -0
  41. data/test/tc_timezone_melbourne.rb +24 -0
  42. data/test/tc_timezone_new_york.rb +24 -0
  43. data/test/{tc_timezone_offset_info.rb → tc_timezone_offset.rb} +27 -27
  44. data/test/tc_timezone_period.rb +113 -90
  45. data/test/tc_timezone_transition.rb +374 -0
  46. data/test/tc_timezone_transition_definition.rb +306 -0
  47. data/test/tc_transition_data_timezone_info.rb +143 -43
  48. data/test/tc_zoneinfo_data_source.rb +69 -5
  49. data/test/tc_zoneinfo_timezone_info.rb +63 -20
  50. data/test/test_utils.rb +27 -7
  51. data/tzinfo.gemspec +21 -0
  52. metadata +61 -38
  53. metadata.gz.sig +3 -0
  54. data/test/tc_timezone_transition_info.rb +0 -471
  55. data/test/zoneinfo/UTC +0 -0
  56. data/test/zoneinfo/localtime +0 -0
@@ -0,0 +1,374 @@
1
+ #--
2
+ # Copyright (c) 2005-2013 Philip Ross
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #++
22
+
23
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
24
+ require 'date'
25
+
26
+ include TZInfo
27
+
28
+ class TCTimezoneTransition < Test::Unit::TestCase
29
+
30
+ class TestTimezoneTransition < TimezoneTransition
31
+ def initialize(offset, previous_offset, at)
32
+ super(offset, previous_offset)
33
+ @at = TimeOrDateTime.wrap(at)
34
+ end
35
+
36
+ def at
37
+ @at
38
+ end
39
+ end
40
+
41
+ def test_offset
42
+ t = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
43
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
44
+
45
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT), t.offset)
46
+ end
47
+
48
+ def test_previous_offset
49
+ t = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
50
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
51
+
52
+ assert_equal(TimezoneOffset.new(3600, 0, :TST), t.previous_offset)
53
+ end
54
+
55
+ def test_datetime
56
+ t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
57
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
58
+ t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
59
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
60
+ t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
61
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
62
+
63
+ assert_equal(DateTime.new(2006, 5, 30, 0, 31, 20), t1.datetime)
64
+ assert_equal(DateTime.new(2006, 5, 30, 0, 31, 20), t2.datetime)
65
+ assert_equal(DateTime.new(2006, 5, 30, 0, 31, 20), t3.datetime)
66
+ end
67
+
68
+ def test_time
69
+ t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
70
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
71
+ t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
72
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
73
+ t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
74
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
75
+
76
+ assert_equal(Time.utc(2006, 5, 30, 0, 31, 20), t1.time)
77
+ assert_equal(Time.utc(2006, 5, 30, 0, 31, 20), t2.time)
78
+ assert_equal(Time.utc(2006, 5, 30, 0, 31, 20), t3.time)
79
+ end
80
+
81
+ def test_local_end_at
82
+ t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
83
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
84
+ t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
85
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
86
+ t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
87
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
88
+
89
+ assert(TimeOrDateTime.new(1148952680).eql?(t1.local_end_at))
90
+ assert(TimeOrDateTime.new(DateTime.new(2006, 5, 30, 1, 31, 20)).eql?(t2.local_end_at))
91
+ assert(TimeOrDateTime.new(Time.utc(2006, 5, 30, 1, 31, 20)).eql?(t3.local_end_at))
92
+ end
93
+
94
+ def test_local_end
95
+ t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
96
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
97
+ t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
98
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
99
+ t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
100
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
101
+
102
+ assert_equal(DateTime.new(2006, 5, 30, 1, 31, 20), t1.local_end)
103
+ assert_equal(DateTime.new(2006, 5, 30, 1, 31, 20), t2.local_end)
104
+ assert_equal(DateTime.new(2006, 5, 30, 1, 31, 20), t3.local_end)
105
+ end
106
+
107
+ def test_local_end_time
108
+ t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
109
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
110
+ t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
111
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
112
+ t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
113
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
114
+
115
+ assert_equal(Time.utc(2006, 5, 30, 1, 31, 20), t1.local_end_time)
116
+ assert_equal(Time.utc(2006, 5, 30, 1, 31, 20), t2.local_end_time)
117
+ assert_equal(Time.utc(2006, 5, 30, 1, 31, 20), t3.local_end_time)
118
+ end
119
+
120
+ def test_local_start_at
121
+ t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
122
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
123
+ t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
124
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
125
+ t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
126
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
127
+
128
+ assert(TimeOrDateTime.new(1148956280).eql?(t1.local_start_at))
129
+ assert(TimeOrDateTime.new(DateTime.new(2006, 5, 30, 2, 31, 20)).eql?(t2.local_start_at))
130
+ assert(TimeOrDateTime.new(Time.utc(2006, 5, 30, 2, 31, 20)).eql?(t3.local_start_at))
131
+ end
132
+
133
+ def test_local_start
134
+ t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
135
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
136
+ t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
137
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
138
+ t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
139
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
140
+
141
+ assert_equal(DateTime.new(2006, 5, 30, 2, 31, 20), t1.local_start)
142
+ assert_equal(DateTime.new(2006, 5, 30, 2, 31, 20), t2.local_start)
143
+ assert_equal(DateTime.new(2006, 5, 30, 2, 31, 20), t3.local_start)
144
+ end
145
+
146
+ def test_local_start_time
147
+ t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
148
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
149
+ t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
150
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
151
+ t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
152
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
153
+
154
+ assert_equal(Time.utc(2006, 5, 30, 2, 31, 20), t1.local_start_time)
155
+ assert_equal(Time.utc(2006, 5, 30, 2, 31, 20), t2.local_start_time)
156
+ assert_equal(Time.utc(2006, 5, 30, 2, 31, 20), t3.local_start_time)
157
+ end
158
+
159
+ if RubyCoreSupport.time_supports_negative
160
+ def test_local_end_at_before_negative_32bit
161
+ t = TestTimezoneTransition.new(TimezoneOffset.new(-7200, 3600, :TDT),
162
+ TimezoneOffset.new(-7200, 0, :TST), -2147482800)
163
+
164
+ if RubyCoreSupport.time_supports_64bit
165
+ assert(TimeOrDateTime.new(-2147490000).eql?(t.local_end_at))
166
+ else
167
+ assert(TimeOrDateTime.new(DateTime.new(1901, 12, 13, 19, 0, 0)).eql?(t.local_end_at))
168
+ end
169
+ end
170
+
171
+ def test_local_start_at_before_negative_32bit
172
+ t = TestTimezoneTransition.new(TimezoneOffset.new(-7200, 3600, :TDT),
173
+ TimezoneOffset.new(-7200, 0, :TST), -2147482800)
174
+
175
+ if RubyCoreSupport.time_supports_64bit
176
+ assert(TimeOrDateTime.new(-2147486400).eql?(t.local_start_at))
177
+ else
178
+ assert(TimeOrDateTime.new(DateTime.new(1901, 12, 13, 20, 0, 0)).eql?(t.local_start_at))
179
+ end
180
+ end
181
+ end
182
+
183
+ def test_local_end_at_before_epoch
184
+ t = TestTimezoneTransition.new(TimezoneOffset.new(-7200, 3600, :TDT),
185
+ TimezoneOffset.new(-7200, 0, :TST), 1800)
186
+
187
+ if RubyCoreSupport.time_supports_negative
188
+ assert(TimeOrDateTime.new(-5400).eql?(t.local_end_at))
189
+ else
190
+ assert(TimeOrDateTime.new(DateTime.new(1969, 12, 31, 22, 30, 0)).eql?(t.local_end_at))
191
+ end
192
+ end
193
+
194
+ def test_local_start_at_before_epoch
195
+ t = TestTimezoneTransition.new(TimezoneOffset.new(-7200, 3600, :TDT),
196
+ TimezoneOffset.new(-7200, 0, :TST), 1800)
197
+
198
+ if RubyCoreSupport.time_supports_negative
199
+ assert(TimeOrDateTime.new(-1800).eql?(t.local_start_at))
200
+ else
201
+ assert(TimeOrDateTime.new(DateTime.new(1969, 12, 31, 23, 30, 0)).eql?(t.local_start_at))
202
+ end
203
+ end
204
+
205
+ def test_local_end_at_after_32bit
206
+ t = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
207
+ TimezoneOffset.new(3600, 0, :TST), 2147482800)
208
+
209
+ if RubyCoreSupport.time_supports_64bit
210
+ assert(TimeOrDateTime.new(2147486400).eql?(t.local_end_at))
211
+ else
212
+ assert(TimeOrDateTime.new(DateTime.new(2038, 1, 19, 4, 0, 0)).eql?(t.local_end_at))
213
+ end
214
+ end
215
+
216
+ def test_local_start_at_after_32bit
217
+ t = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
218
+ TimezoneOffset.new(3600, 0, :TST), 2147482800)
219
+
220
+ if RubyCoreSupport.time_supports_64bit
221
+ assert(TimeOrDateTime.new(2147490000).eql?(t.local_start_at))
222
+ else
223
+ assert(TimeOrDateTime.new(DateTime.new(2038, 1, 19, 5, 0, 0)).eql?(t.local_start_at))
224
+ end
225
+ end
226
+
227
+ def test_equality_timestamp
228
+ t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
229
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
230
+ t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
231
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
232
+ t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
233
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
234
+ t4 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
235
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
236
+ t5 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
237
+ TimezoneOffset.new(3600, 0, :TST), 1148949081)
238
+ t6 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
239
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 1, 31, 21))
240
+ t7 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
241
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 1, 31, 21))
242
+ t8 = TestTimezoneTransition.new(TimezoneOffset.new(3601, 3600, :TDT),
243
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
244
+ t9 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
245
+ TimezoneOffset.new(3601, 0, :TST), 1148949080)
246
+
247
+ assert_equal(true, t1 == t1)
248
+ assert_equal(true, t1 == t2)
249
+ assert_equal(true, t1 == t3)
250
+ assert_equal(true, t1 == t4)
251
+ assert_equal(false, t1 == t5)
252
+ assert_equal(false, t1 == t6)
253
+ assert_equal(false, t1 == t7)
254
+ assert_equal(false, t1 == t8)
255
+ assert_equal(false, t1 == t9)
256
+ assert_equal(false, t1 == Object.new)
257
+
258
+ assert_equal(true, t1.eql?(t1))
259
+ assert_equal(true, t1.eql?(t2))
260
+ assert_equal(false, t1.eql?(t3))
261
+ assert_equal(false, t1.eql?(t4))
262
+ assert_equal(false, t1.eql?(t5))
263
+ assert_equal(false, t1.eql?(t6))
264
+ assert_equal(false, t1.eql?(t7))
265
+ assert_equal(false, t1.eql?(t8))
266
+ assert_equal(false, t1.eql?(t9))
267
+ assert_equal(false, t1.eql?(Object.new))
268
+ end
269
+
270
+ def test_equality_datetime
271
+ t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
272
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
273
+ t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
274
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
275
+ t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
276
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
277
+ t4 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
278
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
279
+ t5 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
280
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 1, 31, 21))
281
+ t6 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
282
+ TimezoneOffset.new(3600, 0, :TST), 1148949081)
283
+ t7 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
284
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 1, 31, 21))
285
+ t8 = TestTimezoneTransition.new(TimezoneOffset.new(3601, 3600, :TDT),
286
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
287
+ t9 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
288
+ TimezoneOffset.new(3601, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
289
+
290
+ assert_equal(true, t1 == t1)
291
+ assert_equal(true, t1 == t2)
292
+ assert_equal(true, t1 == t3)
293
+ assert_equal(true, t1 == t4)
294
+ assert_equal(false, t1 == t5)
295
+ assert_equal(false, t1 == t6)
296
+ assert_equal(false, t1 == t7)
297
+ assert_equal(false, t1 == t8)
298
+ assert_equal(false, t1 == t9)
299
+ assert_equal(false, t1 == Object.new)
300
+
301
+ assert_equal(true, t1.eql?(t1))
302
+ assert_equal(true, t1.eql?(t2))
303
+ assert_equal(false, t1.eql?(t3))
304
+ assert_equal(false, t1.eql?(t4))
305
+ assert_equal(false, t1.eql?(t5))
306
+ assert_equal(false, t1.eql?(t6))
307
+ assert_equal(false, t1.eql?(t7))
308
+ assert_equal(false, t1.eql?(t8))
309
+ assert_equal(false, t1.eql?(t9))
310
+ assert_equal(false, t1.eql?(Object.new))
311
+ end
312
+
313
+ def test_equality_time
314
+ t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
315
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
316
+ t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
317
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
318
+ t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
319
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
320
+ t4 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
321
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
322
+ t5 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
323
+ TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 21))
324
+ t6 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
325
+ TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 1, 31, 21))
326
+ t7 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
327
+ TimezoneOffset.new(3600, 0, :TST), 1148949081)
328
+ t8 = TestTimezoneTransition.new(TimezoneOffset.new(3601, 3600, :TDT),
329
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
330
+ t9 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
331
+ TimezoneOffset.new(3601, 0, :TST), 1148949080)
332
+
333
+ assert_equal(true, t1 == t1)
334
+ assert_equal(true, t1 == t2)
335
+ assert_equal(true, t1 == t3)
336
+ assert_equal(true, t1 == t4)
337
+ assert_equal(false, t1 == t5)
338
+ assert_equal(false, t1 == t6)
339
+ assert_equal(false, t1 == t7)
340
+ assert_equal(false, t1 == t8)
341
+ assert_equal(false, t1 == t9)
342
+ assert_equal(false, t1 == Object.new)
343
+
344
+ assert_equal(true, t1.eql?(t1))
345
+ assert_equal(true, t1.eql?(t2))
346
+ assert_equal(false, t1.eql?(t3))
347
+ assert_equal(false, t1.eql?(t4))
348
+ assert_equal(false, t1.eql?(t5))
349
+ assert_equal(false, t1.eql?(t6))
350
+ assert_equal(false, t1.eql?(t7))
351
+ assert_equal(false, t1.eql?(t8))
352
+ assert_equal(false, t1.eql?(t9))
353
+ assert_equal(false, t1.eql?(Object.new))
354
+ end
355
+
356
+ def test_hash
357
+ t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDTA),
358
+ TimezoneOffset.new(3600, 0, :TSTA), 1148949080)
359
+ t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDTB),
360
+ TimezoneOffset.new(3600, 0, :TSTB), DateTime.new(2006, 5, 30, 1, 31, 20))
361
+ t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDTC),
362
+ TimezoneOffset.new(3600, 0, :TSTC), Time.utc(2006, 5, 30, 1, 31, 20))
363
+
364
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDTA).hash ^
365
+ TimezoneOffset.new(3600, 0, :TSTA).hash ^ TimeOrDateTime.new(1148949080).hash,
366
+ t1.hash)
367
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDTB).hash ^
368
+ TimezoneOffset.new(3600, 0, :TSTB).hash ^ TimeOrDateTime.new(DateTime.new(2006, 5, 30, 1, 31, 20)).hash,
369
+ t2.hash)
370
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDTC).hash ^
371
+ TimezoneOffset.new(3600, 0, :TSTC).hash ^ TimeOrDateTime.new(Time.utc(2006, 5, 30, 1, 31, 20)).hash,
372
+ t3.hash)
373
+ end
374
+ end
@@ -0,0 +1,306 @@
1
+ #--
2
+ # Copyright (c) 2013 Philip Ross
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #++
22
+
23
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
24
+ require 'date'
25
+
26
+ include TZInfo
27
+
28
+ class TCTimezoneTransitionDefinition < Test::Unit::TestCase
29
+ def test_initialize_timestamp_only
30
+ assert_nothing_raised do
31
+ TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
32
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
33
+ end
34
+ end
35
+
36
+ def test_initialize_timestamp_and_datetime
37
+ assert_nothing_raised do
38
+ TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
39
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
40
+ end
41
+ end
42
+
43
+ def test_initialize_datetime_only
44
+ assert_nothing_raised do
45
+ TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
46
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
47
+ end
48
+ end
49
+
50
+ def test_at
51
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
52
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
53
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
54
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
55
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
56
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
57
+
58
+ assert(TimeOrDateTime.new(1148949080).eql?(t1.at))
59
+ assert(TimeOrDateTime.new(DateTime.new(2006, 5, 30, 0, 31, 20)).eql?(t2.at))
60
+ assert(TimeOrDateTime.new(1148949080).eql?(t3.at))
61
+ end
62
+
63
+ def test_at_before_negative_32_bit
64
+ t = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
65
+ TimezoneOffset.new(3600, 0, :TST), -2147483649, 69573092117, 28800)
66
+
67
+ if RubyCoreSupport.time_supports_negative && RubyCoreSupport.time_supports_64bit
68
+ assert(TimeOrDateTime.new(-2147483649).eql?(t.at))
69
+ else
70
+ assert(TimeOrDateTime.new(DateTime.new(1901, 12, 13, 20, 45, 51)).eql?(t.at))
71
+ end
72
+ end
73
+
74
+ def test_at_before_epoch
75
+ t = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
76
+ TimezoneOffset.new(3600, 0, :TST), -1, 210866759999, 86400)
77
+
78
+ if RubyCoreSupport.time_supports_negative
79
+ assert(TimeOrDateTime.new(-1).eql?(t.at))
80
+ else
81
+ assert(TimeOrDateTime.new(DateTime.new(1969, 12, 31, 23, 59, 59)).eql?(t.at))
82
+ end
83
+ end
84
+
85
+ def test_at_after_32bit
86
+ t = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
87
+ TimezoneOffset.new(3600, 0, :TST), 2147483648, 3328347557, 1350)
88
+
89
+ if RubyCoreSupport.time_supports_64bit
90
+ assert(TimeOrDateTime.new(2147483648).eql?(t.at))
91
+ else
92
+ assert(TimeOrDateTime.new(DateTime.new(2038, 1, 19, 3, 14, 8)).eql?(t.at))
93
+ end
94
+ end
95
+
96
+ def test_eql_timestamp
97
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
98
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
99
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
100
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
101
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
102
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
103
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
104
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
105
+ t5 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
106
+ TimezoneOffset.new(3600, 0, :TST), 1148949081)
107
+ t6 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3601, 3600, :TDT),
108
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
109
+ t7 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
110
+ TimezoneOffset.new(3601, 0, :TST), 1148949080)
111
+
112
+ assert_equal(true, t1.eql?(t1))
113
+ assert_equal(true, t1.eql?(t2))
114
+ assert_equal(false, t1.eql?(t3))
115
+ assert_equal(true, t1.eql?(t4))
116
+ assert_equal(false, t1.eql?(t5))
117
+ assert_equal(false, t1.eql?(t6))
118
+ assert_equal(false, t1.eql?(t7))
119
+ assert_equal(false, t1.eql?(Object.new))
120
+ end
121
+
122
+ def test_eql_datetime
123
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
124
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
125
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
126
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
127
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
128
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
129
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
130
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
131
+ t5 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
132
+ TimezoneOffset.new(3600, 0, :TST), 7852433803, 3200)
133
+ t6 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3601, 3600, :TDT),
134
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
135
+ t7 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
136
+ TimezoneOffset.new(3601, 0, :TST), 5300392727, 2160)
137
+
138
+ assert_equal(true, t1.eql?(t1))
139
+ assert_equal(true, t1.eql?(t2))
140
+ assert_equal(false, t1.eql?(t3))
141
+ assert_equal(false, t1.eql?(t4))
142
+ assert_equal(false, t1.eql?(t5))
143
+ assert_equal(false, t1.eql?(t6))
144
+ assert_equal(false, t1.eql?(t7))
145
+ assert_equal(false, t1.eql?(Object.new))
146
+ end
147
+
148
+ def test_eql_timestamp_and_datetime
149
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
150
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
151
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
152
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
153
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
154
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
155
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
156
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
157
+ t5 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
158
+ TimezoneOffset.new(3600, 0, :TST), 1148952681, 7852433803, 3200)
159
+ t6 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3601, 3600, :TDT),
160
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
161
+ t7 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
162
+ TimezoneOffset.new(3601, 0, :TST), 1148949080, 5300392727, 2160)
163
+
164
+ assert_equal(true, t1.eql?(t1))
165
+ assert_equal(true, t1.eql?(t2))
166
+ assert_equal(true, t1.eql?(t3))
167
+ assert_equal(false, t1.eql?(t4))
168
+ assert_equal(false, t1.eql?(t5))
169
+ assert_equal(false, t1.eql?(t6))
170
+ assert_equal(false, t1.eql?(t7))
171
+ assert_equal(false, t1.eql?(Object.new))
172
+ end
173
+
174
+ def test_eql_timestamp_and_datetime_before_negative_32bit
175
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
176
+ TimezoneOffset.new(3600, 0, :TST), -2147483649, 69573092117, 28800)
177
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
178
+ TimezoneOffset.new(3600, 0, :TST), -2147483649, 69573092117, 28800)
179
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
180
+ TimezoneOffset.new(3600, 0, :TST), -2147483649)
181
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
182
+ TimezoneOffset.new(3600, 0, :TST), 69573092117, 28800)
183
+
184
+ assert_equal(true, t1.eql?(t1))
185
+ assert_equal(true, t1.eql?(t2))
186
+
187
+ if RubyCoreSupport.time_supports_negative && RubyCoreSupport.time_supports_64bit
188
+ assert_equal(true, t1.eql?(t3))
189
+ assert_equal(false, t1.eql?(t4))
190
+ assert_equal(true, t3.eql?(t1))
191
+ assert_equal(false, t4.eql?(t1))
192
+ else
193
+ assert_equal(false, t1.eql?(t3))
194
+ assert_equal(true, t1.eql?(t4))
195
+ assert_equal(false, t3.eql?(t1))
196
+ assert_equal(true, t4.eql?(t1))
197
+ end
198
+ end
199
+
200
+ def test_eql_timestamp_and_datetime_before_epoch
201
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
202
+ TimezoneOffset.new(3600, 0, :TST), -1, 210866759999, 86400)
203
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
204
+ TimezoneOffset.new(3600, 0, :TST), -1, 210866759999, 86400)
205
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
206
+ TimezoneOffset.new(3600, 0, :TST), -1)
207
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
208
+ TimezoneOffset.new(3600, 0, :TST), 210866759999, 86400)
209
+
210
+ assert_equal(true, t1.eql?(t1))
211
+ assert_equal(true, t1.eql?(t2))
212
+
213
+ if RubyCoreSupport.time_supports_negative
214
+ assert_equal(true, t1.eql?(t3))
215
+ assert_equal(false, t1.eql?(t4))
216
+ assert_equal(true, t3.eql?(t1))
217
+ assert_equal(false, t4.eql?(t1))
218
+ else
219
+ assert_equal(false, t1.eql?(t3))
220
+ assert_equal(true, t1.eql?(t4))
221
+ assert_equal(false, t3.eql?(t1))
222
+ assert_equal(true, t4.eql?(t1))
223
+ end
224
+ end
225
+
226
+ def test_eql_timestamp_and_datetime_after_32bit
227
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
228
+ TimezoneOffset.new(3600, 0, :TST), 2147483648, 3328347557, 1350)
229
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
230
+ TimezoneOffset.new(3600, 0, :TST), 2147483648, 3328347557, 1350)
231
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
232
+ TimezoneOffset.new(3600, 0, :TST), 2147483648)
233
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
234
+ TimezoneOffset.new(3600, 0, :TST), 3328347557, 1350)
235
+
236
+ assert_equal(true, t1.eql?(t1))
237
+ assert_equal(true, t1.eql?(t2))
238
+
239
+ if RubyCoreSupport.time_supports_64bit
240
+ assert_equal(true, t1.eql?(t3))
241
+ assert_equal(false, t1.eql?(t4))
242
+ assert_equal(true, t3.eql?(t1))
243
+ assert_equal(false, t4.eql?(t1))
244
+ else
245
+ assert_equal(false, t1.eql?(t3))
246
+ assert_equal(true, t1.eql?(t4))
247
+ assert_equal(false, t3.eql?(t1))
248
+ assert_equal(true, t4.eql?(t1))
249
+ end
250
+ end
251
+
252
+ def test_hash
253
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
254
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
255
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
256
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
257
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
258
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
259
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
260
+ TimezoneOffset.new(3600, 0, :TST), -2147483649, 69573092117, 28800)
261
+ t5 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
262
+ TimezoneOffset.new(3600, 0, :TST), -1, 210866759999, 86400)
263
+ t6 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
264
+ TimezoneOffset.new(3600, 0, :TST), 2147483648, 3328347557, 1350)
265
+
266
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
267
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 1148949080.hash ^ nil.hash,
268
+ t1.hash)
269
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
270
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 5300392727.hash ^ 2160.hash,
271
+ t2.hash)
272
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
273
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 1148949080.hash ^ nil.hash,
274
+ t3.hash)
275
+
276
+ if RubyCoreSupport.time_supports_negative && RubyCoreSupport.time_supports_64bit
277
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
278
+ TimezoneOffset.new(3600, 0, :TST).hash ^ -2147483649.hash ^ nil.hash,
279
+ t4.hash)
280
+ else
281
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
282
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 69573092117.hash ^ 28800.hash,
283
+ t4.hash)
284
+ end
285
+
286
+ if RubyCoreSupport.time_supports_negative
287
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
288
+ TimezoneOffset.new(3600, 0, :TST).hash ^ -1.hash ^ nil.hash,
289
+ t5.hash)
290
+ else
291
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
292
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 210866759999.hash ^ 86400.hash,
293
+ t5.hash)
294
+ end
295
+
296
+ if RubyCoreSupport.time_supports_64bit
297
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
298
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 2147483648.hash ^ nil.hash,
299
+ t6.hash)
300
+ else
301
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
302
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 3328347557.hash ^ 1350.hash,
303
+ t6.hash)
304
+ end
305
+ end
306
+ end