tzinfo 1.2.5

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 (111) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +3 -0
  3. data.tar.gz.sig +0 -0
  4. data/.yardopts +6 -0
  5. data/CHANGES.md +786 -0
  6. data/LICENSE +19 -0
  7. data/README.md +151 -0
  8. data/Rakefile +107 -0
  9. data/lib/tzinfo.rb +40 -0
  10. data/lib/tzinfo/country.rb +196 -0
  11. data/lib/tzinfo/country_index_definition.rb +31 -0
  12. data/lib/tzinfo/country_info.rb +42 -0
  13. data/lib/tzinfo/country_timezone.rb +135 -0
  14. data/lib/tzinfo/data_source.rb +190 -0
  15. data/lib/tzinfo/data_timezone.rb +58 -0
  16. data/lib/tzinfo/data_timezone_info.rb +55 -0
  17. data/lib/tzinfo/info_timezone.rb +30 -0
  18. data/lib/tzinfo/linked_timezone.rb +63 -0
  19. data/lib/tzinfo/linked_timezone_info.rb +26 -0
  20. data/lib/tzinfo/offset_rationals.rb +77 -0
  21. data/lib/tzinfo/ruby_core_support.rb +146 -0
  22. data/lib/tzinfo/ruby_country_info.rb +74 -0
  23. data/lib/tzinfo/ruby_data_source.rb +136 -0
  24. data/lib/tzinfo/time_or_datetime.rb +340 -0
  25. data/lib/tzinfo/timezone.rb +669 -0
  26. data/lib/tzinfo/timezone_definition.rb +36 -0
  27. data/lib/tzinfo/timezone_index_definition.rb +54 -0
  28. data/lib/tzinfo/timezone_info.rb +30 -0
  29. data/lib/tzinfo/timezone_offset.rb +101 -0
  30. data/lib/tzinfo/timezone_period.rb +245 -0
  31. data/lib/tzinfo/timezone_proxy.rb +105 -0
  32. data/lib/tzinfo/timezone_transition.rb +130 -0
  33. data/lib/tzinfo/timezone_transition_definition.rb +104 -0
  34. data/lib/tzinfo/transition_data_timezone_info.rb +274 -0
  35. data/lib/tzinfo/zoneinfo_country_info.rb +37 -0
  36. data/lib/tzinfo/zoneinfo_data_source.rb +488 -0
  37. data/lib/tzinfo/zoneinfo_timezone_info.rb +296 -0
  38. data/test/tc_country.rb +234 -0
  39. data/test/tc_country_index_definition.rb +69 -0
  40. data/test/tc_country_info.rb +16 -0
  41. data/test/tc_country_timezone.rb +173 -0
  42. data/test/tc_data_source.rb +218 -0
  43. data/test/tc_data_timezone.rb +99 -0
  44. data/test/tc_data_timezone_info.rb +18 -0
  45. data/test/tc_info_timezone.rb +34 -0
  46. data/test/tc_linked_timezone.rb +155 -0
  47. data/test/tc_linked_timezone_info.rb +23 -0
  48. data/test/tc_offset_rationals.rb +23 -0
  49. data/test/tc_ruby_core_support.rb +168 -0
  50. data/test/tc_ruby_country_info.rb +110 -0
  51. data/test/tc_ruby_data_source.rb +143 -0
  52. data/test/tc_time_or_datetime.rb +654 -0
  53. data/test/tc_timezone.rb +1350 -0
  54. data/test/tc_timezone_definition.rb +113 -0
  55. data/test/tc_timezone_index_definition.rb +73 -0
  56. data/test/tc_timezone_info.rb +11 -0
  57. data/test/tc_timezone_london.rb +143 -0
  58. data/test/tc_timezone_melbourne.rb +142 -0
  59. data/test/tc_timezone_new_york.rb +142 -0
  60. data/test/tc_timezone_offset.rb +126 -0
  61. data/test/tc_timezone_period.rb +555 -0
  62. data/test/tc_timezone_proxy.rb +136 -0
  63. data/test/tc_timezone_transition.rb +366 -0
  64. data/test/tc_timezone_transition_definition.rb +295 -0
  65. data/test/tc_timezone_utc.rb +27 -0
  66. data/test/tc_transition_data_timezone_info.rb +423 -0
  67. data/test/tc_zoneinfo_country_info.rb +78 -0
  68. data/test/tc_zoneinfo_data_source.rb +1195 -0
  69. data/test/tc_zoneinfo_timezone_info.rb +1232 -0
  70. data/test/test_utils.rb +163 -0
  71. data/test/ts_all.rb +7 -0
  72. data/test/ts_all_ruby.rb +5 -0
  73. data/test/ts_all_zoneinfo.rb +7 -0
  74. data/test/tzinfo-data/tzinfo/data.rb +8 -0
  75. data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +89 -0
  76. data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +315 -0
  77. data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +218 -0
  78. data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +19 -0
  79. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +21 -0
  80. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +21 -0
  81. data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +21 -0
  82. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +261 -0
  83. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +186 -0
  84. data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +321 -0
  85. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +265 -0
  86. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +220 -0
  87. data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +16 -0
  88. data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +927 -0
  89. data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +596 -0
  90. data/test/tzinfo-data/tzinfo/data/version.rb +14 -0
  91. data/test/zoneinfo/America/Argentina/Buenos_Aires +0 -0
  92. data/test/zoneinfo/America/New_York +0 -0
  93. data/test/zoneinfo/Australia/Melbourne +0 -0
  94. data/test/zoneinfo/EST +0 -0
  95. data/test/zoneinfo/Etc/UTC +0 -0
  96. data/test/zoneinfo/Europe/Amsterdam +0 -0
  97. data/test/zoneinfo/Europe/Andorra +0 -0
  98. data/test/zoneinfo/Europe/London +0 -0
  99. data/test/zoneinfo/Europe/Paris +0 -0
  100. data/test/zoneinfo/Europe/Prague +0 -0
  101. data/test/zoneinfo/Factory +0 -0
  102. data/test/zoneinfo/iso3166.tab +275 -0
  103. data/test/zoneinfo/leapseconds +61 -0
  104. data/test/zoneinfo/posix/Europe/London +0 -0
  105. data/test/zoneinfo/posixrules +0 -0
  106. data/test/zoneinfo/right/Europe/London +0 -0
  107. data/test/zoneinfo/zone.tab +439 -0
  108. data/test/zoneinfo/zone1970.tab +369 -0
  109. data/tzinfo.gemspec +21 -0
  110. metadata +193 -0
  111. metadata.gz.sig +2 -0
@@ -0,0 +1,295 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
+ require 'date'
3
+
4
+ include TZInfo
5
+
6
+ class TCTimezoneTransitionDefinition < Minitest::Test
7
+ def test_initialize_timestamp_only
8
+ assert_nothing_raised do
9
+ TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
10
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
11
+ end
12
+ end
13
+
14
+ def test_initialize_timestamp_and_datetime
15
+ assert_nothing_raised do
16
+ TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
17
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
18
+ end
19
+ end
20
+
21
+ def test_initialize_datetime_only
22
+ assert_nothing_raised do
23
+ TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
24
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
25
+ end
26
+ end
27
+
28
+ def test_at
29
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
30
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
31
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
32
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
33
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
34
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
35
+
36
+ assert(TimeOrDateTime.new(1148949080).eql?(t1.at))
37
+ assert(TimeOrDateTime.new(DateTime.new(2006, 5, 30, 0, 31, 20)).eql?(t2.at))
38
+ assert(TimeOrDateTime.new(1148949080).eql?(t3.at))
39
+ end
40
+
41
+ def test_at_before_negative_32_bit
42
+ t = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
43
+ TimezoneOffset.new(3600, 0, :TST), -2147483649, 69573092117, 28800)
44
+
45
+ if RubyCoreSupport.time_supports_negative && RubyCoreSupport.time_supports_64bit
46
+ assert(TimeOrDateTime.new(-2147483649).eql?(t.at))
47
+ else
48
+ assert(TimeOrDateTime.new(DateTime.new(1901, 12, 13, 20, 45, 51)).eql?(t.at))
49
+ end
50
+ end
51
+
52
+ def test_at_before_epoch
53
+ t = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
54
+ TimezoneOffset.new(3600, 0, :TST), -1, 210866759999, 86400)
55
+
56
+ if RubyCoreSupport.time_supports_negative
57
+ assert(TimeOrDateTime.new(-1).eql?(t.at))
58
+ else
59
+ assert(TimeOrDateTime.new(DateTime.new(1969, 12, 31, 23, 59, 59)).eql?(t.at))
60
+ end
61
+ end
62
+
63
+ def test_at_after_32bit
64
+ t = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
65
+ TimezoneOffset.new(3600, 0, :TST), 2147483648, 3328347557, 1350)
66
+
67
+ if RubyCoreSupport.time_supports_64bit
68
+ assert(TimeOrDateTime.new(2147483648).eql?(t.at))
69
+ else
70
+ assert(TimeOrDateTime.new(DateTime.new(2038, 1, 19, 3, 14, 8)).eql?(t.at))
71
+ end
72
+ end
73
+
74
+ def test_at_after_freeze
75
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
76
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
77
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
78
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
79
+ t1.freeze
80
+ t2.freeze
81
+ assert(TimeOrDateTime.new(1148949080).eql?(t1.at))
82
+ assert(TimeOrDateTime.new(DateTime.new(2006, 5, 30, 0, 31, 20)).eql?(t2.at))
83
+ end
84
+
85
+ def test_eql_timestamp
86
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
87
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
88
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
89
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
90
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
91
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
92
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
93
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
94
+ t5 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
95
+ TimezoneOffset.new(3600, 0, :TST), 1148949081)
96
+ t6 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3601, 3600, :TDT),
97
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
98
+ t7 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
99
+ TimezoneOffset.new(3601, 0, :TST), 1148949080)
100
+
101
+ assert_equal(true, t1.eql?(t1))
102
+ assert_equal(true, t1.eql?(t2))
103
+ assert_equal(false, t1.eql?(t3))
104
+ assert_equal(true, t1.eql?(t4))
105
+ assert_equal(false, t1.eql?(t5))
106
+ assert_equal(false, t1.eql?(t6))
107
+ assert_equal(false, t1.eql?(t7))
108
+ assert_equal(false, t1.eql?(Object.new))
109
+ end
110
+
111
+ def test_eql_datetime
112
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
113
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
114
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
115
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
116
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
117
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
118
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
119
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
120
+ t5 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
121
+ TimezoneOffset.new(3600, 0, :TST), 7852433803, 3200)
122
+ t6 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3601, 3600, :TDT),
123
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
124
+ t7 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
125
+ TimezoneOffset.new(3601, 0, :TST), 5300392727, 2160)
126
+
127
+ assert_equal(true, t1.eql?(t1))
128
+ assert_equal(true, t1.eql?(t2))
129
+ assert_equal(false, t1.eql?(t3))
130
+ assert_equal(false, t1.eql?(t4))
131
+ assert_equal(false, t1.eql?(t5))
132
+ assert_equal(false, t1.eql?(t6))
133
+ assert_equal(false, t1.eql?(t7))
134
+ assert_equal(false, t1.eql?(Object.new))
135
+ end
136
+
137
+ def test_eql_timestamp_and_datetime
138
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
139
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
140
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
141
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
142
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
143
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
144
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
145
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
146
+ t5 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
147
+ TimezoneOffset.new(3600, 0, :TST), 1148952681, 7852433803, 3200)
148
+ t6 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3601, 3600, :TDT),
149
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
150
+ t7 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
151
+ TimezoneOffset.new(3601, 0, :TST), 1148949080, 5300392727, 2160)
152
+
153
+ assert_equal(true, t1.eql?(t1))
154
+ assert_equal(true, t1.eql?(t2))
155
+ assert_equal(true, t1.eql?(t3))
156
+ assert_equal(false, t1.eql?(t4))
157
+ assert_equal(false, t1.eql?(t5))
158
+ assert_equal(false, t1.eql?(t6))
159
+ assert_equal(false, t1.eql?(t7))
160
+ assert_equal(false, t1.eql?(Object.new))
161
+ end
162
+
163
+ def test_eql_timestamp_and_datetime_before_negative_32bit
164
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
165
+ TimezoneOffset.new(3600, 0, :TST), -2147483649, 69573092117, 28800)
166
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
167
+ TimezoneOffset.new(3600, 0, :TST), -2147483649, 69573092117, 28800)
168
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
169
+ TimezoneOffset.new(3600, 0, :TST), -2147483649)
170
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
171
+ TimezoneOffset.new(3600, 0, :TST), 69573092117, 28800)
172
+
173
+ assert_equal(true, t1.eql?(t1))
174
+ assert_equal(true, t1.eql?(t2))
175
+
176
+ if RubyCoreSupport.time_supports_negative && RubyCoreSupport.time_supports_64bit
177
+ assert_equal(true, t1.eql?(t3))
178
+ assert_equal(false, t1.eql?(t4))
179
+ assert_equal(true, t3.eql?(t1))
180
+ assert_equal(false, t4.eql?(t1))
181
+ else
182
+ assert_equal(false, t1.eql?(t3))
183
+ assert_equal(true, t1.eql?(t4))
184
+ assert_equal(false, t3.eql?(t1))
185
+ assert_equal(true, t4.eql?(t1))
186
+ end
187
+ end
188
+
189
+ def test_eql_timestamp_and_datetime_before_epoch
190
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
191
+ TimezoneOffset.new(3600, 0, :TST), -1, 210866759999, 86400)
192
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
193
+ TimezoneOffset.new(3600, 0, :TST), -1, 210866759999, 86400)
194
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
195
+ TimezoneOffset.new(3600, 0, :TST), -1)
196
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
197
+ TimezoneOffset.new(3600, 0, :TST), 210866759999, 86400)
198
+
199
+ assert_equal(true, t1.eql?(t1))
200
+ assert_equal(true, t1.eql?(t2))
201
+
202
+ if RubyCoreSupport.time_supports_negative
203
+ assert_equal(true, t1.eql?(t3))
204
+ assert_equal(false, t1.eql?(t4))
205
+ assert_equal(true, t3.eql?(t1))
206
+ assert_equal(false, t4.eql?(t1))
207
+ else
208
+ assert_equal(false, t1.eql?(t3))
209
+ assert_equal(true, t1.eql?(t4))
210
+ assert_equal(false, t3.eql?(t1))
211
+ assert_equal(true, t4.eql?(t1))
212
+ end
213
+ end
214
+
215
+ def test_eql_timestamp_and_datetime_after_32bit
216
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
217
+ TimezoneOffset.new(3600, 0, :TST), 2147483648, 3328347557, 1350)
218
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
219
+ TimezoneOffset.new(3600, 0, :TST), 2147483648, 3328347557, 1350)
220
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
221
+ TimezoneOffset.new(3600, 0, :TST), 2147483648)
222
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
223
+ TimezoneOffset.new(3600, 0, :TST), 3328347557, 1350)
224
+
225
+ assert_equal(true, t1.eql?(t1))
226
+ assert_equal(true, t1.eql?(t2))
227
+
228
+ if RubyCoreSupport.time_supports_64bit
229
+ assert_equal(true, t1.eql?(t3))
230
+ assert_equal(false, t1.eql?(t4))
231
+ assert_equal(true, t3.eql?(t1))
232
+ assert_equal(false, t4.eql?(t1))
233
+ else
234
+ assert_equal(false, t1.eql?(t3))
235
+ assert_equal(true, t1.eql?(t4))
236
+ assert_equal(false, t3.eql?(t1))
237
+ assert_equal(true, t4.eql?(t1))
238
+ end
239
+ end
240
+
241
+ def test_hash
242
+ t1 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
243
+ TimezoneOffset.new(3600, 0, :TST), 1148949080)
244
+ t2 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
245
+ TimezoneOffset.new(3600, 0, :TST), 5300392727, 2160)
246
+ t3 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
247
+ TimezoneOffset.new(3600, 0, :TST), 1148949080, 5300392727, 2160)
248
+ t4 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
249
+ TimezoneOffset.new(3600, 0, :TST), -2147483649, 69573092117, 28800)
250
+ t5 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
251
+ TimezoneOffset.new(3600, 0, :TST), -1, 210866759999, 86400)
252
+ t6 = TimezoneTransitionDefinition.new(TimezoneOffset.new(3600, 3600, :TDT),
253
+ TimezoneOffset.new(3600, 0, :TST), 2147483648, 3328347557, 1350)
254
+
255
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
256
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 1148949080.hash ^ nil.hash,
257
+ t1.hash)
258
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
259
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 5300392727.hash ^ 2160.hash,
260
+ t2.hash)
261
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
262
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 1148949080.hash ^ nil.hash,
263
+ t3.hash)
264
+
265
+ if RubyCoreSupport.time_supports_negative && RubyCoreSupport.time_supports_64bit
266
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
267
+ TimezoneOffset.new(3600, 0, :TST).hash ^ -2147483649.hash ^ nil.hash,
268
+ t4.hash)
269
+ else
270
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
271
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 69573092117.hash ^ 28800.hash,
272
+ t4.hash)
273
+ end
274
+
275
+ if RubyCoreSupport.time_supports_negative
276
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
277
+ TimezoneOffset.new(3600, 0, :TST).hash ^ -1.hash ^ nil.hash,
278
+ t5.hash)
279
+ else
280
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
281
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 210866759999.hash ^ 86400.hash,
282
+ t5.hash)
283
+ end
284
+
285
+ if RubyCoreSupport.time_supports_64bit
286
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
287
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 2147483648.hash ^ nil.hash,
288
+ t6.hash)
289
+ else
290
+ assert_equal(TimezoneOffset.new(3600, 3600, :TDT).hash ^
291
+ TimezoneOffset.new(3600, 0, :TST).hash ^ 3328347557.hash ^ 1350.hash,
292
+ t6.hash)
293
+ end
294
+ end
295
+ end
@@ -0,0 +1,27 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
+
3
+ include TZInfo
4
+
5
+ class TCTimezoneUTC < Minitest::Test
6
+ def test_2004
7
+ tz = Timezone.get('UTC')
8
+
9
+ assert_equal(DateTime.new(2004,1,1,0,0,0), tz.utc_to_local(DateTime.new(2004,1,1,0,0,0)))
10
+ assert_equal(DateTime.new(2004,12,31,23,59,59), tz.utc_to_local(DateTime.new(2004,12,31,23,59,59)))
11
+
12
+ assert_equal(DateTime.new(2004,1,1,0,0,0), tz.local_to_utc(DateTime.new(2004,1,1,0,0,0)))
13
+ assert_equal(DateTime.new(2004,12,31,23,59,59), tz.local_to_utc(DateTime.new(2004,12,31,23,59,59)))
14
+
15
+ assert_equal(:UTC, tz.period_for_utc(DateTime.new(2004,1,1,0,0,0)).zone_identifier)
16
+ assert_equal(:UTC, tz.period_for_utc(DateTime.new(2004,12,31,23,59,59)).zone_identifier)
17
+
18
+ assert_equal(:UTC, tz.period_for_local(DateTime.new(2004,1,1,0,0,0)).zone_identifier)
19
+ assert_equal(:UTC, tz.period_for_local(DateTime.new(2004,12,31,23,59,59)).zone_identifier)
20
+
21
+ assert_equal(0, tz.period_for_utc(DateTime.new(2004,1,1,0,0,0)).utc_total_offset)
22
+ assert_equal(0, tz.period_for_utc(DateTime.new(2004,12,31,23,59,59)).utc_total_offset)
23
+
24
+ assert_equal(0, tz.period_for_local(DateTime.new(2004,1,1,0,0,0)).utc_total_offset)
25
+ assert_equal(0, tz.period_for_local(DateTime.new(2004,12,31,23,59,59)).utc_total_offset)
26
+ end
27
+ end
@@ -0,0 +1,423 @@
1
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
+
3
+ include TZInfo
4
+
5
+ class TCTransitionDataTimezoneInfo < Minitest::Test
6
+
7
+ def test_identifier
8
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
9
+ assert_equal('Test/Zone', dti.identifier)
10
+ end
11
+
12
+ def test_offset
13
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
14
+
15
+ assert_nothing_raised do
16
+ dti.offset :o1, -18000, 3600, :TEST
17
+ end
18
+ end
19
+
20
+ def test_offset_already_defined
21
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
22
+ dti.offset :o1, 3600, 0, :TEST
23
+ dti.offset :o2, 1800, 0, :TEST2
24
+
25
+ assert_raises(ArgumentError) { dti.offset :o1, 3600, 3600, :TESTD }
26
+ end
27
+
28
+ def test_transition_timestamp
29
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
30
+ dti.offset :o1, -18000, 3600, :TEST
31
+
32
+ assert_nothing_raised do
33
+ dti.transition 2006, 6, :o1, 1149368400
34
+ end
35
+ end
36
+
37
+ def test_transition_datetime
38
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
39
+ dti.offset :o1, -18000, 3600, :TEST
40
+
41
+ assert_nothing_raised do
42
+ dti.transition 2006, 6, :o1, 19631123, 8
43
+ end
44
+ end
45
+
46
+ def test_transition_timestamp_and_datetime
47
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
48
+ dti.offset :o1, -18000, 3600, :TEST
49
+
50
+ assert_nothing_raised do
51
+ dti.transition 2006, 6, :o1, 1149368400, 19631123, 8
52
+ end
53
+ end
54
+
55
+ def test_transition_invalid_offset
56
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
57
+ dti.offset :o1, -18000, 3600, :TEST
58
+
59
+ dti.transition 2006, 6, :o1, 1149368400
60
+
61
+ assert_raises(ArgumentError) { dti.transition 2006, 6, :o2, 1149454800 }
62
+ end
63
+
64
+ def test_transition_no_offsets
65
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
66
+
67
+ assert_raises(ArgumentError) { dti.transition 2006, 6, :o1, 1149368400 }
68
+ end
69
+
70
+ def test_transition_invalid_order_month
71
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
72
+ dti.offset :o1, -18000, 3600, :TEST
73
+
74
+ dti.transition 2006, 6, :o1, 1149368400
75
+
76
+ assert_raises(ArgumentError) { dti.transition 2006, 5, :o2, 1146690000 }
77
+ end
78
+
79
+ def test_transition_invalid_order_year
80
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
81
+ dti.offset :o1, -18000, 3600, :TEST
82
+
83
+ dti.transition 2006, 6, :o1, 1149368400
84
+
85
+ assert_raises(ArgumentError) { dti.transition 2005, 7, :o2, 1120424400 }
86
+ end
87
+
88
+ def test_period_for_utc
89
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
90
+ dti.offset :o1, -17900, 0, :TESTLMT
91
+ dti.offset :o2, -18000, 3600, :TESTD
92
+ dti.offset :o3, -18000, 0, :TESTS
93
+ dti.offset :o4, -21600, 3600, :TESTD
94
+
95
+ dti.transition 2000, 4, :o2, Time.utc(2000, 4,1,1,0,0).to_i
96
+ dti.transition 2000, 10, :o3, Time.utc(2000,10,1,1,0,0).to_i
97
+ dti.transition 2001, 3, :o2, 58847269, 24 # (2001, 3,1,1,0,0)
98
+ dti.transition 2001, 4, :o4, Time.utc(2001, 4,1,1,0,0).to_i, 58848013, 24
99
+ dti.transition 2001, 10, :o3, Time.utc(2001,10,1,1,0,0).to_i
100
+ dti.transition 2002, 10, :o3, Time.utc(2002,10,1,1,0,0).to_i
101
+ dti.transition 2003, 2, :o2, Time.utc(2003, 2,1,1,0,0).to_i
102
+ dti.transition 2003, 3, :o3, Time.utc(2003, 3,1,1,0,0).to_i
103
+
104
+ o1 = TimezoneOffset.new(-17900, 0, :TESTLMT)
105
+ o2 = TimezoneOffset.new(-18000, 3600, :TESTD)
106
+ o3 = TimezoneOffset.new(-18000, 0, :TESTS)
107
+ o4 = TimezoneOffset.new(-21600, 3600, :TESTD)
108
+
109
+ t1 = TimezoneTransitionDefinition.new(o2, o1, Time.utc(2000, 4,1,1,0,0).to_i)
110
+ t2 = TimezoneTransitionDefinition.new(o3, o2, Time.utc(2000,10,1,1,0,0).to_i)
111
+ t3 = TimezoneTransitionDefinition.new(o2, o3, Time.utc(2001, 3,1,1,0,0).to_i)
112
+ t4 = TimezoneTransitionDefinition.new(o4, o2, Time.utc(2001, 4,1,1,0,0).to_i)
113
+ t5 = TimezoneTransitionDefinition.new(o3, o4, Time.utc(2001,10,1,1,0,0).to_i)
114
+ t6 = TimezoneTransitionDefinition.new(o3, o3, Time.utc(2002,10,1,1,0,0).to_i)
115
+ t7 = TimezoneTransitionDefinition.new(o2, o3, Time.utc(2003, 2,1,1,0,0).to_i)
116
+ t8 = TimezoneTransitionDefinition.new(o3, o2, Time.utc(2003, 3,1,1,0,0).to_i)
117
+
118
+ assert_equal(TimezonePeriod.new(nil, t1), dti.period_for_utc(DateTime.new(1960, 1,1,1, 0, 0)))
119
+ assert_equal(TimezonePeriod.new(nil, t1), dti.period_for_utc(DateTime.new(1999,12,1,0, 0, 0)))
120
+ assert_equal(TimezonePeriod.new(nil, t1), dti.period_for_utc(Time.utc( 2000, 4,1,0,59,59)))
121
+ assert_equal(TimezonePeriod.new(t1, t2), dti.period_for_utc(DateTime.new(2000, 4,1,1, 0, 0)))
122
+ assert_equal(TimezonePeriod.new(t1, t2), dti.period_for_utc(Time.utc( 2000,10,1,0,59,59).to_i))
123
+ assert_equal(TimezonePeriod.new(t2, t3), dti.period_for_utc(Time.utc( 2000,10,1,1, 0, 0)))
124
+ assert_equal(TimezonePeriod.new(t2, t3), dti.period_for_utc(Time.utc( 2001, 3,1,0,59,59)))
125
+ assert_equal(TimezonePeriod.new(t3, t4), dti.period_for_utc(Time.utc( 2001, 3,1,1, 0, 0)))
126
+ assert_equal(TimezonePeriod.new(t3, t4), dti.period_for_utc(Time.utc( 2001, 4,1,0,59,59)))
127
+ assert_equal(TimezonePeriod.new(t4, t5), dti.period_for_utc(Time.utc( 2001, 4,1,1, 0, 0)))
128
+ assert_equal(TimezonePeriod.new(t4, t5), dti.period_for_utc(Time.utc( 2001,10,1,0,59,59)))
129
+ assert_equal(TimezonePeriod.new(t5, t6), dti.period_for_utc(Time.utc( 2001,10,1,1, 0, 0)))
130
+ assert_equal(TimezonePeriod.new(t5, t6), dti.period_for_utc(Time.utc( 2002, 2,1,1, 0, 0)))
131
+ assert_equal(TimezonePeriod.new(t5, t6), dti.period_for_utc(Time.utc( 2002,10,1,0,59,59)))
132
+ assert_equal(TimezonePeriod.new(t6, t7), dti.period_for_utc(Time.utc( 2002,10,1,1, 0, 0)))
133
+ assert_equal(TimezonePeriod.new(t6, t7), dti.period_for_utc(Time.utc( 2003, 2,1,0,59,59)))
134
+ assert_equal(TimezonePeriod.new(t7, t8), dti.period_for_utc(Time.utc( 2003, 2,1,1, 0, 0)))
135
+ assert_equal(TimezonePeriod.new(t7, t8), dti.period_for_utc(Time.utc( 2003, 3,1,0,59,59)))
136
+ assert_equal(TimezonePeriod.new(t8, nil), dti.period_for_utc(Time.utc( 2003, 3,1,1, 0, 0)))
137
+ assert_equal(TimezonePeriod.new(t8, nil), dti.period_for_utc(Time.utc( 2004, 1,1,1, 0, 0)))
138
+ assert_equal(TimezonePeriod.new(t8, nil), dti.period_for_utc(DateTime.new(2050, 1,1,1, 0, 0)))
139
+ end
140
+
141
+ def test_period_for_utc_no_transitions
142
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
143
+ dti.offset :o1, -17900, 0, :TESTLMT
144
+ dti.offset :o2, -18000, 0, :TEST
145
+
146
+ o1 = TimezoneOffset.new(-17900, 0, :TESTLMT)
147
+
148
+ assert_equal(TimezonePeriod.new(nil, nil, o1), dti.period_for_utc(DateTime.new(2005,1,1,0,0,0)))
149
+ assert_equal(TimezonePeriod.new(nil, nil, o1), dti.period_for_utc(Time.utc(2005,1,1,0,0,0)))
150
+ assert_equal(TimezonePeriod.new(nil, nil, o1), dti.period_for_utc(Time.utc(2005,1,1,0,0,0).to_i))
151
+ end
152
+
153
+ def test_period_for_utc_no_offsets
154
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
155
+
156
+ assert_raises(NoOffsetsDefined) { dti.period_for_utc(DateTime.new(2005,1,1,0,0,0)) }
157
+ assert_raises(NoOffsetsDefined) { dti.period_for_utc(Time.utc(2005,1,1,0,0,0)) }
158
+ assert_raises(NoOffsetsDefined) { dti.period_for_utc(Time.utc(2005,1,1,0,0,0).to_i) }
159
+ end
160
+
161
+ def test_periods_for_local
162
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
163
+ dti.offset :o1, -17900, 0, :TESTLMT
164
+ dti.offset :o2, -18000, 3600, :TESTD
165
+ dti.offset :o3, -18000, 0, :TESTS
166
+ dti.offset :o4, -21600, 3600, :TESTD
167
+
168
+ dti.transition 2000, 4, :o2, 58839277, 24 # 2000,4,2,1,0,0
169
+ dti.transition 2000, 10, :o3, Time.utc(2000,10,2,1,0,0).to_i, 58843669, 24
170
+ dti.transition 2001, 3, :o2, Time.utc(2001, 3,2,1,0,0).to_i
171
+ dti.transition 2001, 4, :o4, Time.utc(2001, 4,2,1,0,0).to_i
172
+ dti.transition 2001, 10, :o3, Time.utc(2001,10,2,1,0,0).to_i
173
+ dti.transition 2002, 10, :o3, 58861189, 24 # 2002,10,2,1,0,0
174
+ dti.transition 2003, 2, :o2, Time.utc(2003, 2,2,1,0,0).to_i
175
+
176
+ o1 = TimezoneOffset.new(-17900, 0, :TESTLMT)
177
+ o2 = TimezoneOffset.new(-18000, 3600, :TESTD)
178
+ o3 = TimezoneOffset.new(-18000, 0, :TESTS)
179
+ o4 = TimezoneOffset.new(-21600, 3600, :TESTD)
180
+
181
+ t1 = TimezoneTransitionDefinition.new(o2, o1, Time.utc(2000, 4,2,1,0,0).to_i)
182
+ t2 = TimezoneTransitionDefinition.new(o3, o2, Time.utc(2000,10,2,1,0,0).to_i)
183
+ t3 = TimezoneTransitionDefinition.new(o2, o3, Time.utc(2001, 3,2,1,0,0).to_i)
184
+ t4 = TimezoneTransitionDefinition.new(o4, o2, Time.utc(2001, 4,2,1,0,0).to_i)
185
+ t5 = TimezoneTransitionDefinition.new(o3, o4, Time.utc(2001,10,2,1,0,0).to_i)
186
+ t6 = TimezoneTransitionDefinition.new(o3, o3, Time.utc(2002,10,2,1,0,0).to_i)
187
+ t7 = TimezoneTransitionDefinition.new(o2, o3, Time.utc(2003, 2,2,1,0,0).to_i)
188
+
189
+
190
+ assert_equal([TimezonePeriod.new(nil, t1)], dti.periods_for_local(DateTime.new(1960, 1, 1, 1, 0, 0)))
191
+ assert_equal([TimezonePeriod.new(nil, t1)], dti.periods_for_local(DateTime.new(1999,12, 1, 0, 0, 0)))
192
+ assert_equal([TimezonePeriod.new(nil, t1)], dti.periods_for_local(Time.utc( 2000, 1, 1,10, 0, 0)))
193
+ assert_equal([TimezonePeriod.new(nil, t1)], dti.periods_for_local(Time.utc( 2000, 4, 1,20, 1,39)))
194
+ assert_equal([], dti.periods_for_local(Time.utc( 2000, 4, 1,20, 1,40)))
195
+ assert_equal([], dti.periods_for_local(Time.utc( 2000, 4, 1,20,59,59)))
196
+ assert_equal([TimezonePeriod.new(t1, t2)], dti.periods_for_local(Time.utc( 2000, 4, 1,21, 0, 0)))
197
+ assert_equal([TimezonePeriod.new(t1, t2)], dti.periods_for_local(DateTime.new(2000,10, 1,19,59,59)))
198
+ assert_equal([TimezonePeriod.new(t1, t2),
199
+ TimezonePeriod.new(t2, t3)], dti.periods_for_local(Time.utc( 2000,10, 1,20, 0, 0).to_i))
200
+ assert_equal([TimezonePeriod.new(t1, t2),
201
+ TimezonePeriod.new(t2, t3)], dti.periods_for_local(DateTime.new(2000,10, 1,20,59,59)))
202
+ assert_equal([TimezonePeriod.new(t2, t3)], dti.periods_for_local(Time.utc( 2000,10, 1,21, 0, 0)))
203
+ assert_equal([TimezonePeriod.new(t2, t3)], dti.periods_for_local(Time.utc( 2001, 3, 1,19,59,59)))
204
+ assert_equal([], dti.periods_for_local(Time.utc( 2001, 3, 1,20, 0, 0)))
205
+ assert_equal([], dti.periods_for_local(DateTime.new(2001, 3, 1,20, 30, 0)))
206
+ assert_equal([], dti.periods_for_local(Time.utc( 2001, 3, 1,20,59,59).to_i))
207
+ assert_equal([TimezonePeriod.new(t3, t4)], dti.periods_for_local(Time.utc( 2001, 3, 1,21, 0, 0)))
208
+ assert_equal([TimezonePeriod.new(t3, t4)], dti.periods_for_local(Time.utc( 2001, 4, 1,19,59,59)))
209
+ assert_equal([TimezonePeriod.new(t3, t4),
210
+ TimezonePeriod.new(t4, t5)], dti.periods_for_local(DateTime.new(2001, 4, 1,20, 0, 0)))
211
+ assert_equal([TimezonePeriod.new(t3, t4),
212
+ TimezonePeriod.new(t4, t5)], dti.periods_for_local(Time.utc( 2001, 4, 1,20,59,59)))
213
+ assert_equal([TimezonePeriod.new(t4, t5)], dti.periods_for_local(Time.utc( 2001, 4, 1,21, 0, 0)))
214
+ assert_equal([TimezonePeriod.new(t4, t5)], dti.periods_for_local(Time.utc( 2001,10, 1,19,59,59)))
215
+ assert_equal([TimezonePeriod.new(t5, t6)], dti.periods_for_local(Time.utc( 2001,10, 1,20, 0, 0)))
216
+ assert_equal([TimezonePeriod.new(t5, t6)], dti.periods_for_local(Time.utc( 2002, 2, 1,20, 0, 0)))
217
+ assert_equal([TimezonePeriod.new(t5, t6)], dti.periods_for_local(Time.utc( 2002,10, 1,19,59,59)))
218
+ assert_equal([TimezonePeriod.new(t6, t7)], dti.periods_for_local(Time.utc( 2002,10, 1,20, 0, 0)))
219
+ assert_equal([TimezonePeriod.new(t6, t7)], dti.periods_for_local(Time.utc( 2003, 2, 1,19,59,59)))
220
+ assert_equal([], dti.periods_for_local(Time.utc( 2003, 2, 1,20, 0, 0)))
221
+ assert_equal([], dti.periods_for_local(Time.utc( 2003, 2, 1,20,59,59)))
222
+ assert_equal([TimezonePeriod.new(t7, nil)], dti.periods_for_local(Time.utc( 2003, 2, 1,21, 0, 0)))
223
+ assert_equal([TimezonePeriod.new(t7, nil)], dti.periods_for_local(Time.utc( 2004, 2, 1,20, 0, 0)))
224
+ assert_equal([TimezonePeriod.new(t7, nil)], dti.periods_for_local(DateTime.new(2040, 2, 1,20, 0, 0)))
225
+ end
226
+
227
+ def test_periods_for_local_warsaw
228
+ dti = TransitionDataTimezoneInfo.new('Test/Europe/Warsaw')
229
+ dti.offset :o1, 5040, 0, :LMT
230
+ dti.offset :o2, 5040, 0, :WMT
231
+ dti.offset :o3, 3600, 0, :CET
232
+ dti.offset :o4, 3600, 3600, :CEST
233
+
234
+ dti.transition 1879, 12, :o2, 288925853, 120 # 1879,12,31,22,36,0
235
+ dti.transition 1915, 8, :o3, 290485733, 120 # 1915, 8, 4,22,36,0
236
+ dti.transition 1916, 4, :o4, 29051813, 12 # 1916, 4,30,22, 0,0
237
+
238
+ o1 = TimezoneOffset.new(5040, 0, :LMT)
239
+ o2 = TimezoneOffset.new(5040, 0, :WMT)
240
+ o3 = TimezoneOffset.new(3600, 0, :CET)
241
+ o4 = TimezoneOffset.new(3600, 3600, :CEST)
242
+
243
+ t1 = TimezoneTransitionDefinition.new(o2, o1, 288925853, 120)
244
+ t2 = TimezoneTransitionDefinition.new(o3, o2, 290485733, 120)
245
+ t3 = TimezoneTransitionDefinition.new(o4, o3, 29051813, 12)
246
+
247
+ assert_equal([TimezonePeriod.new(t1, t2),
248
+ TimezonePeriod.new(t2, t3)], dti.periods_for_local(DateTime.new(1915,8,4,23,40,0)))
249
+ end
250
+
251
+ def test_periods_for_local_boundary
252
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
253
+ dti.offset :o1, -3600, 0, :TESTD
254
+ dti.offset :o2, -3600, 0, :TESTS
255
+
256
+ dti.transition 2000, 7, :o2, Time.utc(2000,7,1,0,0,0).to_i
257
+
258
+ o1 = TimezoneOffset.new(-3600, 0, :TESTD)
259
+ o2 = TimezoneOffset.new(-3600, 0, :TESTS)
260
+
261
+ t1 = TimezoneTransitionDefinition.new(o2, o1, Time.utc(2000,7,1,0,0,0).to_i)
262
+
263
+ # 2000-07-01 00:00:00 UTC is 2000-06-30 23:00:00 UTC-1
264
+ # hence to find periods for local times between 2000-06-30 23:00:00
265
+ # and 2000-07-01 00:00:00 a search has to be carried out in the next half
266
+ # year to the one containing the date we are looking for
267
+
268
+ assert_equal([TimezonePeriod.new(nil, t1)], dti.periods_for_local(Time.utc(2000,6,30,22,59,59)))
269
+ assert_equal([TimezonePeriod.new(t1, nil)], dti.periods_for_local(Time.utc(2000,6,30,23, 0, 0)))
270
+ assert_equal([TimezonePeriod.new(t1, nil)], dti.periods_for_local(Time.utc(2000,7, 1, 0, 0, 0)))
271
+ end
272
+
273
+ def test_periods_for_local_no_transitions
274
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
275
+ dti.offset :o1, -17900, 0, :TESTLMT
276
+ dti.offset :o2, -18000, 0, :TEST
277
+
278
+ o1 = TimezoneOffset.new(-17900, 0, :TESTLMT)
279
+
280
+ assert_equal([TimezonePeriod.new(nil, nil, o1)], dti.periods_for_local(DateTime.new(2005,1,1,0,0,0)))
281
+ assert_equal([TimezonePeriod.new(nil, nil, o1)], dti.periods_for_local(Time.utc(2005,1,1,0,0,0)))
282
+ assert_equal([TimezonePeriod.new(nil, nil, o1)], dti.periods_for_local(Time.utc(2005,1,1,0,0,0).to_i))
283
+ end
284
+
285
+ def test_periods_for_local_no_offsets
286
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
287
+
288
+ assert_raises(NoOffsetsDefined) { dti.periods_for_local(DateTime.new(2005,1,1,0,0,0)) }
289
+ assert_raises(NoOffsetsDefined) { dti.periods_for_local(Time.utc(2005,1,1,0,0,0)) }
290
+ assert_raises(NoOffsetsDefined) { dti.periods_for_local(Time.utc(2005,1,1,0,0,0).to_i) }
291
+ end
292
+
293
+ def test_transitions_up_to
294
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
295
+ dti.offset :o1, -17900, 0, :TESTLMT
296
+ dti.offset :o2, -18000, 3600, :TESTD
297
+ dti.offset :o3, -18000, 0, :TESTS
298
+ dti.offset :o4, -21600, 3600, :TESTD
299
+
300
+ dti.transition 2010, 4, :o2, Time.utc(2010, 4,1,1,0,0).to_i
301
+ dti.transition 2010, 10, :o3, Time.utc(2010,10,1,1,0,0).to_i
302
+ dti.transition 2011, 3, :o2, 58934917, 24 # (2011, 3,1,1,0,0)
303
+ dti.transition 2011, 4, :o4, Time.utc(2011, 4,1,1,0,0).to_i, 58935661, 24
304
+ dti.transition 2011, 10, :o3, Time.utc(2011,10,1,1,0,0).to_i
305
+
306
+ o1 = TimezoneOffset.new(-17900, 0, :TESTLMT)
307
+ o2 = TimezoneOffset.new(-18000, 3600, :TESTD)
308
+ o3 = TimezoneOffset.new(-18000, 0, :TESTS)
309
+ o4 = TimezoneOffset.new(-21600, 3600, :TESTD)
310
+
311
+ t1 = TimezoneTransitionDefinition.new(o2, o1, Time.utc(2010, 4,1,1,0,0).to_i)
312
+ t2 = TimezoneTransitionDefinition.new(o3, o2, Time.utc(2010,10,1,1,0,0).to_i)
313
+ t3 = TimezoneTransitionDefinition.new(o2, o3, Time.utc(2011, 3,1,1,0,0).to_i)
314
+ t4 = TimezoneTransitionDefinition.new(o4, o2, Time.utc(2011, 4,1,1,0,0).to_i)
315
+ t5 = TimezoneTransitionDefinition.new(o3, o4, Time.utc(2011,10,1,1,0,0).to_i)
316
+
317
+ assert_equal([], dti.transitions_up_to(Time.utc(2010,4,1,1,0,0)))
318
+ assert_equal([], dti.transitions_up_to(Time.utc(2010,4,1,1,0,0), Time.utc(2000,1,1,0,0,0)))
319
+ assert_equal([t1], dti.transitions_up_to(Time.utc(2010,4,1,1,0,1)))
320
+ assert_equal([t1], dti.transitions_up_to(Time.utc(2010,4,1,1,0,1), Time.utc(2000,1,1,0,0,0)))
321
+ assert_equal([t2,t3,t4], dti.transitions_up_to(Time.utc(2011,4,1,1,0,1), Time.utc(2010,10,1,1,0,0)))
322
+ assert_equal([t2,t3,t4], dti.transitions_up_to(Time.utc(2011,10,1,1,0,0), Time.utc(2010,4,1,1,0,1)))
323
+ assert_equal([t3], dti.transitions_up_to(Time.utc(2011,4,1,1,0,0), Time.utc(2010,10,1,1,0,1)))
324
+ assert_equal([], dti.transitions_up_to(Time.utc(2011,3,1,1,0,0), Time.utc(2010,10,1,1,0,1)))
325
+ assert_equal([t1,t2,t3,t4], dti.transitions_up_to(Time.utc(2011,10,1,1,0,0)))
326
+ assert_equal([t1,t2,t3,t4,t5], dti.transitions_up_to(Time.utc(2011,10,1,1,0,1)))
327
+ assert_equal([t1,t2,t3,t4,t5], dti.transitions_up_to(Time.utc(2011,10,1,1,0,0,1)))
328
+ assert_equal([t1,t2,t3,t4,t5], dti.transitions_up_to(Time.utc(2011,10,1,1,0,1), Time.utc(2010,4,1,1,0,0)))
329
+ assert_equal([t2,t3,t4,t5], dti.transitions_up_to(Time.utc(2011,10,1,1,0,1), Time.utc(2010,4,1,1,0,1)))
330
+ assert_equal([t2,t3,t4,t5], dti.transitions_up_to(Time.utc(2011,10,1,1,0,1), Time.utc(2010,4,1,1,0,0,1)))
331
+ assert_equal([t5], dti.transitions_up_to(Time.utc(2015,1,1,0,0,0), Time.utc(2011,10,1,1,0,0)))
332
+ assert_equal([], dti.transitions_up_to(Time.utc(2015,1,1,0,0,0), Time.utc(2011,10,1,1,0,1)))
333
+
334
+ assert_equal([], dti.transitions_up_to(Time.utc(2010,4,1,1,0,0).to_i))
335
+ assert_equal([], dti.transitions_up_to(Time.utc(2010,4,1,1,0,0).to_i, Time.utc(2000,1,1,0,0,0).to_i))
336
+ assert_equal([t1], dti.transitions_up_to(Time.utc(2010,4,1,1,0,1).to_i))
337
+ assert_equal([t1], dti.transitions_up_to(Time.utc(2010,4,1,1,0,1).to_i, Time.utc(2000,1,1,0,0,0).to_i))
338
+ assert_equal([t2,t3,t4], dti.transitions_up_to(Time.utc(2011,4,1,1,0,1).to_i, Time.utc(2010,10,1,1,0,0).to_i))
339
+ assert_equal([t2,t3,t4], dti.transitions_up_to(Time.utc(2011,10,1,1,0,0).to_i, Time.utc(2010,4,1,1,0,1).to_i))
340
+ assert_equal([t3], dti.transitions_up_to(Time.utc(2011,4,1,1,0,0).to_i, Time.utc(2010,10,1,1,0,1).to_i))
341
+ assert_equal([], dti.transitions_up_to(Time.utc(2011,3,1,1,0,0).to_i, Time.utc(2010,10,1,1,0,1).to_i))
342
+ assert_equal([t1,t2,t3,t4], dti.transitions_up_to(Time.utc(2011,10,1,1,0,0).to_i))
343
+ assert_equal([t1,t2,t3,t4,t5], dti.transitions_up_to(Time.utc(2011,10,1,1,0,1).to_i))
344
+ assert_equal([t1,t2,t3,t4,t5], dti.transitions_up_to(Time.utc(2011,10,1,1,0,1).to_i, Time.utc(2010,4,1,1,0,0).to_i))
345
+ assert_equal([t2,t3,t4,t5], dti.transitions_up_to(Time.utc(2011,10,1,1,0,1).to_i, Time.utc(2010,4,1,1,0,1).to_i))
346
+ assert_equal([t5], dti.transitions_up_to(Time.utc(2015,1,1,0,0,0).to_i, Time.utc(2011,10,1,1,0,0).to_i))
347
+ assert_equal([], dti.transitions_up_to(Time.utc(2015,1,1,0,0,0).to_i, Time.utc(2011,10,1,1,0,1).to_i))
348
+
349
+ assert_equal([], dti.transitions_up_to(DateTime.new(2010,4,1,1,0,0)))
350
+ assert_equal([], dti.transitions_up_to(DateTime.new(2010,4,1,1,0,0), DateTime.new(2000,1,1,0,0,0)))
351
+ assert_equal([t1], dti.transitions_up_to(DateTime.new(2010,4,1,1,0,1)))
352
+ assert_equal([t1], dti.transitions_up_to(DateTime.new(2010,4,1,1,0,1), DateTime.new(2000,1,1,0,0,0)))
353
+ assert_equal([t2,t3,t4], dti.transitions_up_to(DateTime.new(2011,4,1,1,0,1), DateTime.new(2010,10,1,1,0,0)))
354
+ assert_equal([t2,t3,t4], dti.transitions_up_to(DateTime.new(2011,10,1,1,0,0), DateTime.new(2010,4,1,1,0,1)))
355
+ assert_equal([t3], dti.transitions_up_to(DateTime.new(2011,4,1,1,0,0), DateTime.new(2010,10,1,1,0,1)))
356
+ assert_equal([], dti.transitions_up_to(DateTime.new(2011,3,1,1,0,0), DateTime.new(2010,10,1,1,0,1)))
357
+ assert_equal([t1,t2,t3,t4], dti.transitions_up_to(DateTime.new(2011,10,1,1,0,0)))
358
+ assert_equal([t1,t2,t3,t4,t5], dti.transitions_up_to(DateTime.new(2011,10,1,1,0,1)))
359
+ assert_equal([t1,t2,t3,t4,t5], dti.transitions_up_to(DateTime.new(2011,10,1,1,0,Rational(DATETIME_RESOLUTION,1000000))))
360
+ assert_equal([t1,t2,t3,t4,t5], dti.transitions_up_to(DateTime.new(2011,10,1,1,0,1), DateTime.new(2010,4,1,1,0,0)))
361
+ assert_equal([t2,t3,t4,t5], dti.transitions_up_to(DateTime.new(2011,10,1,1,0,1), DateTime.new(2010,4,1,1,0,1)))
362
+ assert_equal([t2,t3,t4,t5], dti.transitions_up_to(DateTime.new(2011,10,1,1,0,1), DateTime.new(2010,4,1,1,0,Rational(DATETIME_RESOLUTION,1000000))))
363
+ assert_equal([t5], dti.transitions_up_to(DateTime.new(2015,1,1,0,0,0), DateTime.new(2011,10,1,1,0,0)))
364
+ assert_equal([], dti.transitions_up_to(DateTime.new(2015,1,1,0,0,0), DateTime.new(2011,10,1,1,0,1)))
365
+ end
366
+
367
+ def test_transitions_up_to_no_transitions
368
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
369
+ dti.offset :o1, -17900, 0, :TESTLMT
370
+
371
+ assert_equal([], dti.transitions_up_to(Time.utc(2015,1,1,0,0,0)))
372
+ assert_equal([], dti.transitions_up_to(Time.utc(2015,1,1,0,0,0).to_i))
373
+ assert_equal([], dti.transitions_up_to(DateTime.new(2015,1,1,0,0,0)))
374
+ end
375
+
376
+ def test_transitions_up_to_utc_to_not_greater_than_utc_from
377
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
378
+ dti.offset :o1, -17900, 0, :TESTLMT
379
+
380
+ assert_raises(ArgumentError) do
381
+ dti.transitions_up_to(Time.utc(2012,8,1,0,0,0), Time.utc(2013,8,1,0,0,0))
382
+ end
383
+
384
+ assert_raises(ArgumentError) do
385
+ dti.transitions_up_to(Time.utc(2012,8,1,0,0,0).to_i, Time.utc(2012,8,1,0,0,0).to_i)
386
+ end
387
+
388
+ assert_raises(ArgumentError) do
389
+ dti.transitions_up_to(DateTime.new(2012,8,1,0,0,0), DateTime.new(2012,8,1,0,0,0))
390
+ end
391
+ end
392
+
393
+ def test_datetime_and_timestamp_use
394
+ dti = TransitionDataTimezoneInfo.new('Test/Zone')
395
+ dti.offset :o1, 0, 0, :TESTS
396
+ dti.offset :o2, 0, 3600, :TESTD
397
+
398
+ dti.transition 1901, 12, :o2, -2147483649, 69573092117, 28800
399
+ dti.transition 1969, 12, :o1, -1, 210866759999, 86400
400
+ dti.transition 2001, 9, :o2, 1000000000, 529666909, 216
401
+ dti.transition 2038, 1, :o1, 2147483648, 3328347557, 1350
402
+
403
+ if RubyCoreSupport.time_supports_negative && RubyCoreSupport.time_supports_64bit
404
+ assert(dti.period_for_utc(DateTime.new(1901,12,13,20,45,51)).start_transition.at.eql?(TimeOrDateTime.new(-2147483649)))
405
+ else
406
+ assert(dti.period_for_utc(DateTime.new(1901,12,13,20,45,51)).start_transition.at.eql?(TimeOrDateTime.new(DateTime.new(1901,12,13,20,45,51))))
407
+ end
408
+
409
+ if RubyCoreSupport.time_supports_negative
410
+ assert(dti.period_for_utc(DateTime.new(1969,12,31,23,59,59)).start_transition.at.eql?(TimeOrDateTime.new(-1)))
411
+ else
412
+ assert(dti.period_for_utc(DateTime.new(1969,12,31,23,59,59)).start_transition.at.eql?(TimeOrDateTime.new(DateTime.new(1969,12,31,23,59,59))))
413
+ end
414
+
415
+ assert(dti.period_for_utc(DateTime.new(2001,9,9,2,46,40)).start_transition.at.eql?(TimeOrDateTime.new(1000000000)))
416
+
417
+ if RubyCoreSupport.time_supports_64bit
418
+ assert(dti.period_for_utc(DateTime.new(2038,1,19,3,14,8)).start_transition.at.eql?(TimeOrDateTime.new(2147483648)))
419
+ else
420
+ assert(dti.period_for_utc(DateTime.new(2038,1,19,3,14,8)).start_transition.at.eql?(TimeOrDateTime.new(DateTime.new(2038,1,19,3,14,8))))
421
+ end
422
+ end
423
+ end