tzinfo 1.2.5 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.yardopts +3 -0
  4. data/CHANGES.md +607 -377
  5. data/LICENSE +13 -13
  6. data/README.md +368 -113
  7. data/lib/tzinfo/annual_rules.rb +71 -0
  8. data/lib/tzinfo/country.rb +141 -129
  9. data/lib/tzinfo/country_timezone.rb +70 -112
  10. data/lib/tzinfo/data_source.rb +400 -144
  11. data/lib/tzinfo/data_sources/constant_offset_data_timezone_info.rb +56 -0
  12. data/lib/tzinfo/data_sources/country_info.rb +42 -0
  13. data/lib/tzinfo/data_sources/data_timezone_info.rb +91 -0
  14. data/lib/tzinfo/data_sources/linked_timezone_info.rb +33 -0
  15. data/lib/tzinfo/data_sources/posix_time_zone_parser.rb +181 -0
  16. data/lib/tzinfo/data_sources/ruby_data_source.rb +145 -0
  17. data/lib/tzinfo/data_sources/timezone_info.rb +47 -0
  18. data/lib/tzinfo/data_sources/transitions_data_timezone_info.rb +214 -0
  19. data/lib/tzinfo/data_sources/zoneinfo_data_source.rb +596 -0
  20. data/lib/tzinfo/data_sources/zoneinfo_reader.rb +486 -0
  21. data/lib/tzinfo/data_sources.rb +8 -0
  22. data/lib/tzinfo/data_timezone.rb +33 -47
  23. data/lib/tzinfo/datetime_with_offset.rb +153 -0
  24. data/lib/tzinfo/format1/country_definer.rb +17 -0
  25. data/lib/tzinfo/format1/country_index_definition.rb +64 -0
  26. data/lib/tzinfo/format1/timezone_definer.rb +64 -0
  27. data/lib/tzinfo/format1/timezone_definition.rb +39 -0
  28. data/lib/tzinfo/format1/timezone_index_definition.rb +77 -0
  29. data/lib/tzinfo/format1.rb +10 -0
  30. data/lib/tzinfo/format2/country_definer.rb +68 -0
  31. data/lib/tzinfo/format2/country_index_definer.rb +68 -0
  32. data/lib/tzinfo/format2/country_index_definition.rb +46 -0
  33. data/lib/tzinfo/format2/timezone_definer.rb +94 -0
  34. data/lib/tzinfo/format2/timezone_definition.rb +73 -0
  35. data/lib/tzinfo/format2/timezone_index_definer.rb +45 -0
  36. data/lib/tzinfo/format2/timezone_index_definition.rb +55 -0
  37. data/lib/tzinfo/format2.rb +10 -0
  38. data/lib/tzinfo/info_timezone.rb +26 -21
  39. data/lib/tzinfo/linked_timezone.rb +33 -52
  40. data/lib/tzinfo/offset_timezone_period.rb +42 -0
  41. data/lib/tzinfo/string_deduper.rb +118 -0
  42. data/lib/tzinfo/time_with_offset.rb +154 -0
  43. data/lib/tzinfo/timestamp.rb +552 -0
  44. data/lib/tzinfo/timestamp_with_offset.rb +85 -0
  45. data/lib/tzinfo/timezone.rb +989 -498
  46. data/lib/tzinfo/timezone_offset.rb +84 -74
  47. data/lib/tzinfo/timezone_period.rb +151 -217
  48. data/lib/tzinfo/timezone_proxy.rb +70 -79
  49. data/lib/tzinfo/timezone_transition.rb +77 -109
  50. data/lib/tzinfo/transition_rule.rb +455 -0
  51. data/lib/tzinfo/transitions_timezone_period.rb +63 -0
  52. data/lib/tzinfo/untaint_ext.rb +18 -0
  53. data/lib/tzinfo/version.rb +7 -0
  54. data/lib/tzinfo/with_offset.rb +61 -0
  55. data/lib/tzinfo.rb +74 -29
  56. data.tar.gz.sig +0 -0
  57. metadata +72 -122
  58. metadata.gz.sig +0 -0
  59. data/Rakefile +0 -107
  60. data/lib/tzinfo/country_index_definition.rb +0 -31
  61. data/lib/tzinfo/country_info.rb +0 -42
  62. data/lib/tzinfo/data_timezone_info.rb +0 -55
  63. data/lib/tzinfo/linked_timezone_info.rb +0 -26
  64. data/lib/tzinfo/offset_rationals.rb +0 -77
  65. data/lib/tzinfo/ruby_core_support.rb +0 -146
  66. data/lib/tzinfo/ruby_country_info.rb +0 -74
  67. data/lib/tzinfo/ruby_data_source.rb +0 -136
  68. data/lib/tzinfo/time_or_datetime.rb +0 -340
  69. data/lib/tzinfo/timezone_definition.rb +0 -36
  70. data/lib/tzinfo/timezone_index_definition.rb +0 -54
  71. data/lib/tzinfo/timezone_info.rb +0 -30
  72. data/lib/tzinfo/timezone_transition_definition.rb +0 -104
  73. data/lib/tzinfo/transition_data_timezone_info.rb +0 -274
  74. data/lib/tzinfo/zoneinfo_country_info.rb +0 -37
  75. data/lib/tzinfo/zoneinfo_data_source.rb +0 -488
  76. data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -296
  77. data/test/tc_country.rb +0 -234
  78. data/test/tc_country_index_definition.rb +0 -69
  79. data/test/tc_country_info.rb +0 -16
  80. data/test/tc_country_timezone.rb +0 -173
  81. data/test/tc_data_source.rb +0 -218
  82. data/test/tc_data_timezone.rb +0 -99
  83. data/test/tc_data_timezone_info.rb +0 -18
  84. data/test/tc_info_timezone.rb +0 -34
  85. data/test/tc_linked_timezone.rb +0 -155
  86. data/test/tc_linked_timezone_info.rb +0 -23
  87. data/test/tc_offset_rationals.rb +0 -23
  88. data/test/tc_ruby_core_support.rb +0 -168
  89. data/test/tc_ruby_country_info.rb +0 -110
  90. data/test/tc_ruby_data_source.rb +0 -143
  91. data/test/tc_time_or_datetime.rb +0 -654
  92. data/test/tc_timezone.rb +0 -1350
  93. data/test/tc_timezone_definition.rb +0 -113
  94. data/test/tc_timezone_index_definition.rb +0 -73
  95. data/test/tc_timezone_info.rb +0 -11
  96. data/test/tc_timezone_london.rb +0 -143
  97. data/test/tc_timezone_melbourne.rb +0 -142
  98. data/test/tc_timezone_new_york.rb +0 -142
  99. data/test/tc_timezone_offset.rb +0 -126
  100. data/test/tc_timezone_period.rb +0 -555
  101. data/test/tc_timezone_proxy.rb +0 -136
  102. data/test/tc_timezone_transition.rb +0 -366
  103. data/test/tc_timezone_transition_definition.rb +0 -295
  104. data/test/tc_timezone_utc.rb +0 -27
  105. data/test/tc_transition_data_timezone_info.rb +0 -423
  106. data/test/tc_zoneinfo_country_info.rb +0 -78
  107. data/test/tc_zoneinfo_data_source.rb +0 -1195
  108. data/test/tc_zoneinfo_timezone_info.rb +0 -1232
  109. data/test/test_utils.rb +0 -163
  110. data/test/ts_all.rb +0 -7
  111. data/test/ts_all_ruby.rb +0 -5
  112. data/test/ts_all_zoneinfo.rb +0 -7
  113. data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +0 -89
  114. data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +0 -315
  115. data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +0 -218
  116. data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +0 -19
  117. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +0 -21
  118. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +0 -21
  119. data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +0 -21
  120. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +0 -261
  121. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +0 -186
  122. data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +0 -321
  123. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +0 -265
  124. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +0 -220
  125. data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +0 -16
  126. data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +0 -927
  127. data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +0 -596
  128. data/test/tzinfo-data/tzinfo/data/version.rb +0 -14
  129. data/test/tzinfo-data/tzinfo/data.rb +0 -8
  130. data/test/zoneinfo/America/Argentina/Buenos_Aires +0 -0
  131. data/test/zoneinfo/America/New_York +0 -0
  132. data/test/zoneinfo/Australia/Melbourne +0 -0
  133. data/test/zoneinfo/EST +0 -0
  134. data/test/zoneinfo/Etc/UTC +0 -0
  135. data/test/zoneinfo/Europe/Amsterdam +0 -0
  136. data/test/zoneinfo/Europe/Andorra +0 -0
  137. data/test/zoneinfo/Europe/London +0 -0
  138. data/test/zoneinfo/Europe/Paris +0 -0
  139. data/test/zoneinfo/Europe/Prague +0 -0
  140. data/test/zoneinfo/Factory +0 -0
  141. data/test/zoneinfo/iso3166.tab +0 -275
  142. data/test/zoneinfo/leapseconds +0 -61
  143. data/test/zoneinfo/posix/Europe/London +0 -0
  144. data/test/zoneinfo/posixrules +0 -0
  145. data/test/zoneinfo/right/Europe/London +0 -0
  146. data/test/zoneinfo/zone.tab +0 -439
  147. data/test/zoneinfo/zone1970.tab +0 -369
  148. data/tzinfo.gemspec +0 -21
@@ -1,296 +0,0 @@
1
- module TZInfo
2
- # An InvalidZoneinfoFile exception is raised if an attempt is made to load an
3
- # invalid zoneinfo file.
4
- class InvalidZoneinfoFile < StandardError
5
- end
6
-
7
- # Represents a timezone defined by a compiled zoneinfo TZif (\0, 2 or 3) file.
8
- #
9
- # @private
10
- class ZoneinfoTimezoneInfo < TransitionDataTimezoneInfo #:nodoc:
11
-
12
- # Minimum supported timestamp (inclusive).
13
- #
14
- # Time.utc(1700, 1, 1).to_i
15
- MIN_TIMESTAMP = -8520336000
16
-
17
- # Maximum supported timestamp (exclusive).
18
- #
19
- # Time.utc(2500, 1, 1).to_i
20
- MAX_TIMESTAMP = 16725225600
21
-
22
- # Constructs the new ZoneinfoTimezoneInfo with an identifier and path
23
- # to the file.
24
- def initialize(identifier, file_path)
25
- super(identifier)
26
-
27
- File.open(file_path, 'rb') do |file|
28
- parse(file)
29
- end
30
- end
31
-
32
- private
33
- # Unpack will return unsigned 32-bit integers. Translate to
34
- # signed 32-bit.
35
- def make_signed_int32(long)
36
- long >= 0x80000000 ? long - 0x100000000 : long
37
- end
38
-
39
- # Unpack will return a 64-bit integer as two unsigned 32-bit integers
40
- # (most significant first). Translate to signed 64-bit
41
- def make_signed_int64(high, low)
42
- unsigned = (high << 32) | low
43
- unsigned >= 0x8000000000000000 ? unsigned - 0x10000000000000000 : unsigned
44
- end
45
-
46
- # Read bytes from file and check that the correct number of bytes could
47
- # be read. Raises InvalidZoneinfoFile if the number of bytes didn't match
48
- # the number requested.
49
- def check_read(file, bytes)
50
- result = file.read(bytes)
51
-
52
- unless result && result.length == bytes
53
- raise InvalidZoneinfoFile, "Expected #{bytes} bytes reading '#{file.path}', but got #{result ? result.length : 0} bytes"
54
- end
55
-
56
- result
57
- end
58
-
59
- # Zoneinfo files don't include the offset from standard time (std_offset)
60
- # for DST periods. Derive the base offset (utc_offset) where DST is
61
- # observed from either the previous or next non-DST period.
62
- #
63
- # Returns the index of the offset to be used prior to the first
64
- # transition.
65
- def derive_offsets(transitions, offsets)
66
- # The first non-DST offset (if there is one) is the offset observed
67
- # before the first transition. Fallback to the first DST offset if there
68
- # are no non-DST offsets.
69
- first_non_dst_offset_index = offsets.index {|o| !o[:is_dst] }
70
- first_offset_index = first_non_dst_offset_index || 0
71
- return first_offset_index if transitions.empty?
72
-
73
- # Determine the utc_offset of the next non-dst offset at each transition.
74
- utc_offset_from_next = nil
75
-
76
- transitions.reverse_each do |transition|
77
- offset = offsets[transition[:offset]]
78
- if offset[:is_dst]
79
- transition[:utc_offset_from_next] = utc_offset_from_next if utc_offset_from_next
80
- else
81
- utc_offset_from_next = offset[:utc_total_offset]
82
- end
83
- end
84
-
85
- utc_offset_from_previous = first_non_dst_offset_index ? offsets[first_non_dst_offset_index][:utc_total_offset] : nil
86
- defined_offsets = {}
87
-
88
- transitions.each do |transition|
89
- offset_index = transition[:offset]
90
- offset = offsets[offset_index]
91
- utc_total_offset = offset[:utc_total_offset]
92
-
93
- if offset[:is_dst]
94
- utc_offset_from_next = transition[:utc_offset_from_next]
95
-
96
- difference_to_previous = (utc_total_offset - (utc_offset_from_previous || utc_total_offset)).abs
97
- difference_to_next = (utc_total_offset - (utc_offset_from_next || utc_total_offset)).abs
98
-
99
- utc_offset = if difference_to_previous == 3600
100
- utc_offset_from_previous
101
- elsif difference_to_next == 3600
102
- utc_offset_from_next
103
- elsif difference_to_previous > 0 && difference_to_next > 0
104
- difference_to_previous < difference_to_next ? utc_offset_from_previous : utc_offset_from_next
105
- elsif difference_to_previous > 0
106
- utc_offset_from_previous
107
- elsif difference_to_next > 0
108
- utc_offset_from_next
109
- else
110
- # No difference, assume a 1 hour offset from standard time.
111
- utc_total_offset - 3600
112
- end
113
-
114
- if !offset[:utc_offset]
115
- offset[:utc_offset] = utc_offset
116
- defined_offsets[offset] = offset_index
117
- elsif offset[:utc_offset] != utc_offset
118
- # An earlier transition has already derived a different
119
- # utc_offset. Define a new offset or reuse an existing identically
120
- # defined offset.
121
- new_offset = offset.dup
122
- new_offset[:utc_offset] = utc_offset
123
-
124
- offset_index = defined_offsets[new_offset]
125
-
126
- unless offset_index
127
- offsets << new_offset
128
- offset_index = offsets.length - 1
129
- defined_offsets[new_offset] = offset_index
130
- end
131
-
132
- transition[:offset] = offset_index
133
- end
134
- else
135
- utc_offset_from_previous = utc_total_offset
136
- end
137
- end
138
-
139
- first_offset_index
140
- end
141
-
142
- # Defines an offset for the timezone based on the given index and offset
143
- # Hash.
144
- def define_offset(index, offset)
145
- utc_total_offset = offset[:utc_total_offset]
146
- utc_offset = offset[:utc_offset]
147
-
148
- if utc_offset
149
- # DST offset with base utc_offset derived by derive_offsets.
150
- std_offset = utc_total_offset - utc_offset
151
- elsif offset[:is_dst]
152
- # DST offset unreferenced by a transition (offset in use before the
153
- # first transition). No derived base UTC offset, so assume 1 hour
154
- # DST.
155
- utc_offset = utc_total_offset - 3600
156
- std_offset = 3600
157
- else
158
- # Non-DST offset.
159
- utc_offset = utc_total_offset
160
- std_offset = 0
161
- end
162
-
163
- offset index, utc_offset, std_offset, offset[:abbr].untaint.to_sym
164
- end
165
-
166
- # Parses a zoneinfo file and intializes the DataTimezoneInfo structures.
167
- def parse(file)
168
- magic, version, ttisgmtcnt, ttisstdcnt, leapcnt, timecnt, typecnt, charcnt =
169
- check_read(file, 44).unpack('a4 a x15 NNNNNN')
170
-
171
- if magic != 'TZif'
172
- raise InvalidZoneinfoFile, "The file '#{file.path}' does not start with the expected header."
173
- end
174
-
175
- if (version == '2' || version == '3') && RubyCoreSupport.time_supports_64bit
176
- # Skip the first 32-bit section and read the header of the second 64-bit section
177
- file.seek(timecnt * 5 + typecnt * 6 + charcnt + leapcnt * 8 + ttisgmtcnt + ttisstdcnt, IO::SEEK_CUR)
178
-
179
- prev_version = version
180
-
181
- magic, version, ttisgmtcnt, ttisstdcnt, leapcnt, timecnt, typecnt, charcnt =
182
- check_read(file, 44).unpack('a4 a x15 NNNNNN')
183
-
184
- unless magic == 'TZif' && (version == prev_version)
185
- raise InvalidZoneinfoFile, "The file '#{file.path}' contains an invalid 64-bit section header."
186
- end
187
-
188
- using_64bit = true
189
- elsif version != '3' && version != '2' && version != "\0"
190
- raise InvalidZoneinfoFile, "The file '#{file.path}' contains a version of the zoneinfo format that is not currently supported."
191
- else
192
- using_64bit = false
193
- end
194
-
195
- unless leapcnt == 0
196
- raise InvalidZoneinfoFile, "The zoneinfo file '#{file.path}' contains leap second data. TZInfo requires zoneinfo files that omit leap seconds."
197
- end
198
-
199
- transitions = []
200
-
201
- if using_64bit
202
- timecnt.times do |i|
203
- high, low = check_read(file, 8).unpack('NN'.freeze)
204
- transition_time = make_signed_int64(high, low)
205
- transitions << {:at => transition_time}
206
- end
207
- else
208
- timecnt.times do |i|
209
- transition_time = make_signed_int32(check_read(file, 4).unpack('N'.freeze)[0])
210
- transitions << {:at => transition_time}
211
- end
212
- end
213
-
214
- timecnt.times do |i|
215
- localtime_type = check_read(file, 1).unpack('C'.freeze)[0]
216
- transitions[i][:offset] = localtime_type
217
- end
218
-
219
- offsets = []
220
-
221
- typecnt.times do |i|
222
- gmtoff, isdst, abbrind = check_read(file, 6).unpack('NCC'.freeze)
223
- gmtoff = make_signed_int32(gmtoff)
224
- isdst = isdst == 1
225
- offset = {:utc_total_offset => gmtoff, :is_dst => isdst, :abbr_index => abbrind}
226
-
227
- unless isdst
228
- offset[:utc_offset] = gmtoff
229
- offset[:std_offset] = 0
230
- end
231
-
232
- offsets << offset
233
- end
234
-
235
- abbrev = check_read(file, charcnt)
236
-
237
- offsets.each do |o|
238
- abbrev_start = o[:abbr_index]
239
- raise InvalidZoneinfoFile, "Abbreviation index is out of range in file '#{file.path}'" unless abbrev_start < abbrev.length
240
-
241
- abbrev_end = abbrev.index("\0", abbrev_start)
242
- raise InvalidZoneinfoFile, "Missing abbreviation null terminator in file '#{file.path}'" unless abbrev_end
243
-
244
- o[:abbr] = RubyCoreSupport.force_encoding(abbrev[abbrev_start...abbrev_end], 'UTF-8')
245
- end
246
-
247
- transitions.each do |t|
248
- if t[:offset] < 0 || t[:offset] >= offsets.length
249
- raise InvalidZoneinfoFile, "Invalid offset referenced by transition in file '#{file.path}'."
250
- end
251
- end
252
-
253
- # Derive the offsets from standard time (std_offset).
254
- first_offset_index = derive_offsets(transitions, offsets)
255
-
256
- define_offset(first_offset_index, offsets[first_offset_index])
257
-
258
- offsets.each_with_index do |o, i|
259
- define_offset(i, o) unless i == first_offset_index
260
- end
261
-
262
- if !using_64bit && !RubyCoreSupport.time_supports_negative
263
- # Filter out transitions that are not supported by Time on this
264
- # platform.
265
-
266
- # Move the last transition before the epoch up to the epoch. This
267
- # allows for accurate conversions for all supported timestamps on the
268
- # platform.
269
-
270
- before_epoch, after_epoch = transitions.partition {|t| t[:at] < 0}
271
-
272
- if before_epoch.length > 0 && after_epoch.length > 0 && after_epoch.first[:at] != 0
273
- last_before = before_epoch.last
274
- last_before[:at] = 0
275
- transitions = [last_before] + after_epoch
276
- else
277
- transitions = after_epoch
278
- end
279
- end
280
-
281
- # Ignore transitions that occur outside of a defined window. The
282
- # transition index cannot handle a large range of transition times.
283
- #
284
- # This is primarily intended to ignore the far in the past transition
285
- # added in zic 2014c (at timestamp -2**63 in zic 2014c and at the
286
- # approximate time of the big bang from zic 2014d).
287
- transitions.each do |t|
288
- at = t[:at]
289
- if at >= MIN_TIMESTAMP && at < MAX_TIMESTAMP
290
- time = Time.at(at).utc
291
- transition time.year, time.mon, t[:offset], at
292
- end
293
- end
294
- end
295
- end
296
- end
data/test/tc_country.rb DELETED
@@ -1,234 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
-
3
- include TZInfo
4
-
5
- class TCCountry < Minitest::Test
6
- def setup
7
- @orig_data_source = DataSource.get
8
- Country.send :init_countries
9
- end
10
-
11
- def teardown
12
- DataSource.set(@orig_data_source)
13
- end
14
-
15
- def test_get_valid
16
- c = Country.get('GB')
17
-
18
- assert c
19
- assert_equal('GB', c.code)
20
- end
21
-
22
- def test_get_not_exist
23
- assert_raises(InvalidCountryCode) {
24
- Country.get('ZZ')
25
- }
26
- end
27
-
28
- def test_get_invalid
29
- assert_raises(InvalidCountryCode) {
30
- Country.get('../Countries/GB')
31
- }
32
- end
33
-
34
- def test_get_nil
35
- assert_raises(InvalidCountryCode) {
36
- Country.get(nil)
37
- }
38
- end
39
-
40
- def test_get_case
41
- assert_raises(InvalidCountryCode) {
42
- Country.get('gb')
43
- }
44
- end
45
-
46
- def test_get_tainted_loaded
47
- Country.get('GB')
48
-
49
- safe_test do
50
- code = 'GB'.dup.taint
51
- assert(code.tainted?)
52
- country = Country.get(code)
53
- assert_equal('GB', country.code)
54
- assert(code.tainted?)
55
- end
56
- end
57
-
58
- def test_get_tainted_and_frozen_loaded
59
- Country.get('GB')
60
-
61
- safe_test do
62
- country = Country.get('GB'.dup.taint.freeze)
63
- assert_equal('GB', country.code)
64
- end
65
- end
66
-
67
- def test_get_tainted_not_previously_loaded
68
- safe_test do
69
- code = 'GB'.dup.taint
70
- assert(code.tainted?)
71
- country = Country.get(code)
72
- assert_equal('GB', country.code)
73
- assert(code.tainted?)
74
- end
75
- end
76
-
77
- def test_get_tainted_and_frozen_not_previously_loaded
78
- safe_test do
79
- country = Country.get('GB'.dup.taint.freeze)
80
- assert_equal('GB', country.code)
81
- end
82
- end
83
-
84
- def test_new_nil
85
- assert_raises(InvalidCountryCode) {
86
- Country.new(nil)
87
- }
88
- end
89
-
90
- def test_new_arg
91
- c = Country.new('GB')
92
- assert_same(Country.get('GB'), c)
93
- end
94
-
95
- def test_new_arg_not_exist
96
- assert_raises(InvalidCountryCode) {
97
- Country.new('ZZ')
98
- }
99
- end
100
-
101
- def test_all_codes
102
- all_codes = Country.all_codes
103
- assert_kind_of(Array, all_codes)
104
- end
105
-
106
- def test_all
107
- all = Country.all
108
- assert_equal(Country.all_codes, all.collect {|c| c.code})
109
- end
110
-
111
- def test_code
112
- assert_equal('US', Country.get('US').code)
113
- end
114
-
115
- def test_name
116
- assert_kind_of(String, Country.get('US').name)
117
- end
118
-
119
- def test_to_s
120
- assert_equal(Country.get('US').name, Country.get('US').to_s)
121
- assert_equal(Country.get('GB').name, Country.get('GB').to_s)
122
- end
123
-
124
- def test_zone_identifiers
125
- zone_names = Country.get('US').zone_names
126
- assert_kind_of(Array, zone_names)
127
- assert_equal(true, zone_names.frozen?)
128
- end
129
-
130
- def test_zone_names
131
- assert_equal(Country.get('US').zone_identifiers, Country.get('US').zone_names)
132
- end
133
-
134
- def test_zones
135
- zones = Country.get('US').zones
136
- assert_kind_of(Array, zones)
137
- assert_equal(Country.get('US').zone_identifiers, zones.collect {|z| z.identifier})
138
-
139
- zones.each {|z| assert_kind_of(TimezoneProxy, z)}
140
- end
141
-
142
- def test_zone_info
143
- zones = Country.get('US').zone_info
144
- assert_kind_of(Array, zones)
145
- assert_equal(true, zones.frozen?)
146
-
147
- assert_equal(Country.get('US').zone_identifiers, zones.collect {|z| z.identifier})
148
- assert_equal(Country.get('US').zone_identifiers, zones.collect {|z| z.timezone.identifier})
149
-
150
- zones.each {|z| assert_kind_of(CountryTimezone, z)}
151
- end
152
-
153
- def test_compare
154
- assert_equal(0, Country.get('GB') <=> Country.get('GB'))
155
- assert_equal(-1, Country.get('GB') <=> Country.get('US'))
156
- assert_equal(1, Country.get('US') <=> Country.get('GB'))
157
- assert_equal(-1, Country.get('FR') <=> Country.get('US'))
158
- assert_equal(1, Country.get('US') <=> Country.get('FR'))
159
- end
160
-
161
- def test_compare_non_comparable
162
- assert_nil(Country.get('GB') <=> Object.new)
163
- end
164
-
165
- def test_equality
166
- assert_equal(true, Country.get('GB') == Country.get('GB'))
167
- assert_equal(false, Country.get('GB') == Country.get('US'))
168
- assert(!(Country.get('GB') == Object.new))
169
- end
170
-
171
- def test_eql
172
- assert_equal(true, Country.get('GB').eql?(Country.get('GB')))
173
- assert_equal(false, Country.get('GB').eql?(Country.get('US')))
174
- assert(!Country.get('GB').eql?(Object.new))
175
- end
176
-
177
- def test_hash
178
- assert_equal('GB'.hash, Country.get('GB').hash)
179
- assert_equal('US'.hash, Country.get('US').hash)
180
- end
181
-
182
- def test_marshal
183
- c = Country.get('US')
184
-
185
- # Should get back the same instance because load calls Country.get.
186
- assert_same(c, Marshal.load(Marshal.dump(c)))
187
- end
188
-
189
- def test_reload
190
- # If country gets reloaded for some reason, it needs to force a reload of
191
- # the country index.
192
-
193
- assert_equal('US', Country.get('US').code)
194
-
195
- # Suppress redefined method warnings.
196
- without_warnings do
197
- load 'tzinfo/country.rb'
198
- end
199
-
200
- assert_equal('US', Country.get('US').code)
201
- end
202
-
203
- def test_get_missing_data_source
204
- DataSource.set(DataSource.new)
205
-
206
- assert_raises(InvalidDataSource) do
207
- Country.get('GB')
208
- end
209
- end
210
-
211
- def test_new_missing_data_source
212
- DataSource.set(DataSource.new)
213
-
214
- assert_raises(InvalidDataSource) do
215
- Country.new('GB')
216
- end
217
- end
218
-
219
- def test_all_codes_missing_data_source
220
- DataSource.set(DataSource.new)
221
-
222
- assert_raises(InvalidDataSource) do
223
- Country.all_codes
224
- end
225
- end
226
-
227
- def test_all_missing_data_source
228
- DataSource.set(DataSource.new)
229
-
230
- assert_raises(InvalidDataSource) do
231
- Country.all
232
- end
233
- end
234
- end
@@ -1,69 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
-
3
- include TZInfo
4
-
5
- class TCCountryIndexDefinition < Minitest::Test
6
-
7
- module CountriesTest1
8
- include CountryIndexDefinition
9
-
10
- country 'ZZ', 'Country One' do |c|
11
- c.timezone 'Test/Zone/1', 3, 2, 41,20
12
- end
13
-
14
- country 'AA', 'Aland' do |c|
15
- c.timezone 'Test/Zone/3', 71,30, 358, 15
16
- c.timezone 'Test/Zone/2', 41, 20, 211, 30
17
- end
18
-
19
- country 'TE', 'Three'
20
- end
21
-
22
- module CountriesTest2
23
- include CountryIndexDefinition
24
-
25
- country 'CO', 'First Country' do |c|
26
- end
27
- end
28
-
29
- def test_module_1
30
- hash = CountriesTest1.countries
31
- assert_equal(3, hash.length)
32
- assert_equal(true, hash.frozen?)
33
-
34
- zz = hash['ZZ']
35
- aa = hash['AA']
36
- te = hash['TE']
37
-
38
- assert_kind_of(RubyCountryInfo, zz)
39
- assert_equal('ZZ', zz.code)
40
- assert_equal('Country One', zz.name)
41
- assert_equal(1, zz.zones.length)
42
- assert_equal('Test/Zone/1', zz.zones[0].identifier)
43
-
44
- assert_kind_of(RubyCountryInfo, aa)
45
- assert_equal('AA', aa.code)
46
- assert_equal('Aland', aa.name)
47
- assert_equal(2, aa.zones.length)
48
- assert_equal('Test/Zone/3', aa.zones[0].identifier)
49
- assert_equal('Test/Zone/2', aa.zones[1].identifier)
50
-
51
- assert_kind_of(RubyCountryInfo, te)
52
- assert_equal('TE', te.code)
53
- assert_equal('Three', te.name)
54
- assert_equal(0, te.zones.length)
55
- end
56
-
57
- def test_module_2
58
- hash = CountriesTest2.countries
59
- assert_equal(1, hash.length)
60
- assert_equal(true, hash.frozen?)
61
-
62
- co = hash['CO']
63
-
64
- assert_kind_of(RubyCountryInfo, co)
65
- assert_equal('CO', co.code)
66
- assert_equal('First Country', co.name)
67
- assert_equal(0, co.zones.length)
68
- end
69
- end
@@ -1,16 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
-
3
- include TZInfo
4
-
5
- class TCCountryInfo < Minitest::Test
6
-
7
- def test_code
8
- ci = CountryInfo.new('ZZ', 'Zzz') {|c| }
9
- assert_equal('ZZ', ci.code)
10
- end
11
-
12
- def test_name
13
- ci = CountryInfo.new('ZZ', 'Zzz') {|c| }
14
- assert_equal('Zzz', ci.name)
15
- end
16
- end