tzinfo 1.2.7 → 2.0.2

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