tzinfo 1.2.10 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.yardopts +3 -0
  4. data/CHANGES.md +573 -391
  5. data/LICENSE +12 -12
  6. data/README.md +368 -114
  7. data/lib/tzinfo/annual_rules.rb +32 -12
  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 -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/transition_rule.rb +207 -77
  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 +82 -40
  56. data.tar.gz.sig +0 -0
  57. metadata +49 -104
  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/posix_time_zone_parser.rb +0 -136
  66. data/lib/tzinfo/ruby_core_support.rb +0 -169
  67. data/lib/tzinfo/ruby_country_info.rb +0 -74
  68. data/lib/tzinfo/ruby_data_source.rb +0 -140
  69. data/lib/tzinfo/time_or_datetime.rb +0 -351
  70. data/lib/tzinfo/timezone_definition.rb +0 -36
  71. data/lib/tzinfo/timezone_index_definition.rb +0 -54
  72. data/lib/tzinfo/timezone_info.rb +0 -30
  73. data/lib/tzinfo/timezone_transition_definition.rb +0 -104
  74. data/lib/tzinfo/transition_data_timezone_info.rb +0 -274
  75. data/lib/tzinfo/zoneinfo_country_info.rb +0 -37
  76. data/lib/tzinfo/zoneinfo_data_source.rb +0 -512
  77. data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -520
  78. data/test/assets/payload.rb +0 -1
  79. data/test/tc_annual_rules.rb +0 -95
  80. data/test/tc_country.rb +0 -238
  81. data/test/tc_country_index_definition.rb +0 -69
  82. data/test/tc_country_info.rb +0 -16
  83. data/test/tc_country_timezone.rb +0 -173
  84. data/test/tc_data_source.rb +0 -218
  85. data/test/tc_data_timezone.rb +0 -99
  86. data/test/tc_data_timezone_info.rb +0 -18
  87. data/test/tc_info_timezone.rb +0 -34
  88. data/test/tc_linked_timezone.rb +0 -155
  89. data/test/tc_linked_timezone_info.rb +0 -23
  90. data/test/tc_offset_rationals.rb +0 -23
  91. data/test/tc_posix_time_zone_parser.rb +0 -261
  92. data/test/tc_ruby_core_support.rb +0 -168
  93. data/test/tc_ruby_country_info.rb +0 -110
  94. data/test/tc_ruby_data_source.rb +0 -173
  95. data/test/tc_time_or_datetime.rb +0 -674
  96. data/test/tc_timezone.rb +0 -1361
  97. data/test/tc_timezone_definition.rb +0 -113
  98. data/test/tc_timezone_index_definition.rb +0 -73
  99. data/test/tc_timezone_info.rb +0 -11
  100. data/test/tc_timezone_london.rb +0 -143
  101. data/test/tc_timezone_melbourne.rb +0 -142
  102. data/test/tc_timezone_new_york.rb +0 -142
  103. data/test/tc_timezone_offset.rb +0 -126
  104. data/test/tc_timezone_period.rb +0 -555
  105. data/test/tc_timezone_proxy.rb +0 -136
  106. data/test/tc_timezone_transition.rb +0 -366
  107. data/test/tc_timezone_transition_definition.rb +0 -295
  108. data/test/tc_timezone_utc.rb +0 -27
  109. data/test/tc_transition_data_timezone_info.rb +0 -433
  110. data/test/tc_transition_rule.rb +0 -663
  111. data/test/tc_zoneinfo_country_info.rb +0 -78
  112. data/test/tc_zoneinfo_data_source.rb +0 -1223
  113. data/test/tc_zoneinfo_timezone_info.rb +0 -2153
  114. data/test/test_utils.rb +0 -208
  115. data/test/ts_all.rb +0 -7
  116. data/test/ts_all_ruby.rb +0 -5
  117. data/test/ts_all_zoneinfo.rb +0 -9
  118. data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +0 -89
  119. data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +0 -327
  120. data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +0 -230
  121. data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +0 -19
  122. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +0 -21
  123. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +0 -21
  124. data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +0 -21
  125. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +0 -273
  126. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +0 -198
  127. data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +0 -333
  128. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +0 -277
  129. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +0 -235
  130. data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +0 -16
  131. data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +0 -940
  132. data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +0 -609
  133. data/test/tzinfo-data/tzinfo/data/version.rb +0 -20
  134. data/test/tzinfo-data/tzinfo/data.rb +0 -8
  135. data/test/zoneinfo/America/Argentina/Buenos_Aires +0 -0
  136. data/test/zoneinfo/America/New_York +0 -0
  137. data/test/zoneinfo/Australia/Melbourne +0 -0
  138. data/test/zoneinfo/EST +0 -0
  139. data/test/zoneinfo/Etc/UTC +0 -0
  140. data/test/zoneinfo/Europe/Amsterdam +0 -0
  141. data/test/zoneinfo/Europe/Andorra +0 -0
  142. data/test/zoneinfo/Europe/London +0 -0
  143. data/test/zoneinfo/Europe/Paris +0 -0
  144. data/test/zoneinfo/Europe/Prague +0 -0
  145. data/test/zoneinfo/Factory +0 -0
  146. data/test/zoneinfo/iso3166.tab +0 -274
  147. data/test/zoneinfo/leapseconds +0 -78
  148. data/test/zoneinfo/posix/Europe/London +0 -0
  149. data/test/zoneinfo/posixrules +0 -0
  150. data/test/zoneinfo/right/Europe/London +0 -0
  151. data/test/zoneinfo/zone.tab +0 -452
  152. data/test/zoneinfo/zone1970.tab +0 -384
  153. data/tzinfo.gemspec +0 -21
data/test/tc_country.rb DELETED
@@ -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
@@ -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
@@ -1,173 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
-
3
- include TZInfo
4
-
5
- class TCCountryTimezone < Minitest::Test
6
- def test_identifier_new!
7
- ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
8
- assert_equal('Europe/London', ct.identifier)
9
- end
10
-
11
- def test_identifier_new
12
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
13
- assert_equal('Europe/London', ct.identifier)
14
- end
15
-
16
- def test_latitude_new!
17
- ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
18
- assert_equal(Rational(2059, 40), ct.latitude)
19
- end
20
-
21
- def test_latitude_after_freeze_new!
22
- ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
23
- ct.freeze
24
- assert_equal(Rational(2059, 40), ct.latitude)
25
- end
26
-
27
- def test_latitude_new
28
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
29
- assert_equal(Rational(2059, 40), ct.latitude)
30
- end
31
-
32
- def test_longitude_new!
33
- ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
34
- assert_equal(Rational(-5, 16), ct.longitude)
35
- end
36
-
37
- def test_longitude_after_freeze_new!
38
- ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
39
- ct.freeze
40
- assert_equal(Rational(-5, 16), ct.longitude)
41
- end
42
-
43
- def test_longitude_new
44
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
45
- assert_equal(Rational(-5, 16), ct.longitude)
46
- end
47
-
48
- def test_description_omit_new!
49
- ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
50
- assert_nil(ct.description)
51
- end
52
-
53
- def test_description_omit_new
54
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
55
- assert_nil(ct.description)
56
- end
57
-
58
- def test_description_nil_new!
59
- ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16, nil)
60
- assert_nil(ct.description)
61
- end
62
-
63
- def test_description_nil_new
64
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16), nil)
65
- assert_nil(ct.description)
66
- end
67
-
68
- def test_description_new!
69
- ct = CountryTimezone.new!('America/New_York', 48857, 1200, -266423, 3600, 'Eastern Time')
70
- assert_equal('Eastern Time', ct.description)
71
- end
72
-
73
- def test_description_new
74
- ct = CountryTimezone.new('America/New_York', Rational(48857, 1200), Rational(-266423, 3600), 'Eastern Time')
75
- assert_equal('Eastern Time', ct.description)
76
- end
77
-
78
- def test_timezone
79
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
80
- assert_kind_of(TimezoneProxy, ct.timezone)
81
- assert_equal('Europe/London', ct.timezone.identifier)
82
- end
83
-
84
- def test_description_or_friendly_idenfier_no_description
85
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
86
- assert_equal('London', ct.description_or_friendly_identifier)
87
- end
88
-
89
- def test_description_or_friendly_idenfier_description
90
- ct = CountryTimezone.new('America/New_York', Rational(48857, 1200), Rational(-266423, 3600), 'Eastern Time')
91
- assert_equal('Eastern Time', ct.description_or_friendly_identifier)
92
- end
93
-
94
- def test_equality_1
95
- ct1 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
96
- ct2 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
97
- ct3 = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
98
- ct4 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16, 'Description')
99
- ct5 = CountryTimezone.new!('Europe/LondonB', 2059, 40, -5, 16)
100
- ct6 = CountryTimezone.new!('Europe/London', 2060, 40, -5, 16)
101
- ct7 = CountryTimezone.new!('Europe/London', 2059, 40, -6, 16)
102
-
103
- assert_equal(true, ct1 == ct1)
104
- assert_equal(true, ct1 == ct2)
105
- assert_equal(true, ct1 == ct3)
106
- assert_equal(false, ct1 == ct4)
107
- assert_equal(false, ct1 == ct5)
108
- assert_equal(false, ct1 == ct6)
109
- assert_equal(false, ct1 == ct7)
110
- end
111
-
112
- def test_equality_2
113
- ct1 = CountryTimezone.new!('America/New_York', 48857, 1200, -266423, 3600, 'Eastern Time')
114
- ct2 = CountryTimezone.new!('America/New_York', 48857, 1200, -266423, 3600, 'Eastern Time2')
115
-
116
- assert_equal(true, ct1 == ct1)
117
- assert_equal(false, ct1 == ct2)
118
- end
119
-
120
- def test_equality_non_country_timezone
121
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
122
-
123
- assert_equal(false, ct == Object.new)
124
- end
125
-
126
- def test_eql_1
127
- ct1 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
128
- ct2 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
129
- ct3 = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
130
- ct4 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16, 'Description')
131
- ct5 = CountryTimezone.new!('Europe/LondonB', 2059, 40, -5, 16)
132
- ct6 = CountryTimezone.new!('Europe/London', 2060, 40, -5, 16)
133
- ct7 = CountryTimezone.new!('Europe/London', 2059, 40, -6, 16)
134
-
135
- assert_equal(true, ct1.eql?(ct1))
136
- assert_equal(true, ct1.eql?(ct2))
137
- assert_equal(true, ct1.eql?(ct3))
138
- assert_equal(false, ct1.eql?(ct4))
139
- assert_equal(false, ct1.eql?(ct5))
140
- assert_equal(false, ct1.eql?(ct6))
141
- assert_equal(false, ct1.eql?(ct7))
142
- end
143
-
144
- def test_eql_2
145
- ct1 = CountryTimezone.new!('America/New_York', 48857, 1200, -266423, 3600, 'Eastern Time')
146
- ct2 = CountryTimezone.new!('America/New_York', 48857, 1200, -266423, 3600, 'Eastern Time2')
147
-
148
- assert_equal(true, ct1.eql?(ct1))
149
- assert_equal(false, ct1.eql?(ct2))
150
- end
151
-
152
- def test_eql_non_country_timezone
153
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
154
-
155
- assert_equal(false, ct.eql?(Object.new))
156
- end
157
-
158
- def test_hash_new!
159
- ct1 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
160
- ct2 = CountryTimezone.new!('America/New_York', 48857, 1200, -266423, 3600, 'Eastern Time')
161
-
162
- assert_equal('Europe/London'.hash ^ 2059.hash ^ 40.hash ^ -5.hash ^ 16.hash ^ nil.hash, ct1.hash)
163
- assert_equal('America/New_York'.hash ^ 48857.hash ^ 1200.hash ^ -266423.hash ^ 3600.hash ^ 'Eastern Time'.hash, ct2.hash)
164
- end
165
-
166
- def test_hash_new
167
- ct1 = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
168
- ct2 = CountryTimezone.new('America/New_York', Rational(48857, 1200), Rational(-266423, 3600), 'Eastern Time')
169
-
170
- assert_equal('Europe/London'.hash ^ 2059.hash ^ 40.hash ^ -5.hash ^ 16.hash ^ nil.hash, ct1.hash)
171
- assert_equal('America/New_York'.hash ^ 48857.hash ^ 1200.hash ^ -266423.hash ^ 3600.hash ^ 'Eastern Time'.hash, ct2.hash)
172
- end
173
- end
@@ -1,218 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
- require 'tmpdir'
3
-
4
- include TZInfo
5
-
6
- class TCDataSource < Minitest::Test
7
- class InitDataSource < DataSource
8
- end
9
-
10
- class DummyDataSource < DataSource
11
- end
12
-
13
- def setup
14
- @orig_data_source = DataSource.get
15
- DataSource.set(InitDataSource.new)
16
- @orig_search_path = ZoneinfoDataSource.search_path.clone
17
- end
18
-
19
- def teardown
20
- DataSource.set(@orig_data_source)
21
- ZoneinfoDataSource.search_path = @orig_search_path
22
- end
23
-
24
- def test_get
25
- data_source = DataSource.get
26
- assert_kind_of(InitDataSource, data_source)
27
- end
28
-
29
- def test_get_default_ruby_only
30
- code = <<-EOF
31
- require 'tmpdir'
32
-
33
- begin
34
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
35
- TZInfo::ZoneinfoDataSource.search_path = [dir]
36
-
37
- puts TZInfo::DataSource.get.class
38
- end
39
- rescue Exception => e
40
- puts "Unexpected exception: \#{e}"
41
- end
42
- EOF
43
-
44
- assert_sub_process_returns(['TZInfo::RubyDataSource'], code, [TZINFO_TEST_DATA_DIR])
45
- end
46
-
47
- def test_get_default_zoneinfo_only
48
- code = <<-EOF
49
- require 'tmpdir'
50
-
51
- begin
52
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
53
- TZInfo::ZoneinfoDataSource.search_path = [dir, '#{TZINFO_TEST_ZONEINFO_DIR}']
54
-
55
- puts TZInfo::DataSource.get.class
56
- puts TZInfo::DataSource.get.zoneinfo_dir
57
- end
58
- rescue Exception => e
59
- puts "Unexpected exception: \#{e}"
60
- end
61
- EOF
62
-
63
- assert_sub_process_returns(
64
- ['TZInfo::ZoneinfoDataSource', TZINFO_TEST_ZONEINFO_DIR],
65
- code)
66
- end
67
-
68
- def test_get_default_ruby_and_zoneinfo
69
- code = <<-EOF
70
- begin
71
- TZInfo::ZoneinfoDataSource.search_path = ['#{TZINFO_TEST_ZONEINFO_DIR}']
72
-
73
- puts TZInfo::DataSource.get.class
74
- rescue Exception => e
75
- puts "Unexpected exception: \#{e}"
76
- end
77
- EOF
78
-
79
- assert_sub_process_returns(['TZInfo::RubyDataSource'], code, [TZINFO_TEST_DATA_DIR])
80
- end
81
-
82
- def test_get_default_no_data
83
- code = <<-EOF
84
- require 'tmpdir'
85
-
86
- begin
87
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
88
- TZInfo::ZoneinfoDataSource.search_path = [dir]
89
-
90
- begin
91
- data_source = TZInfo::DataSource.get
92
- puts "No exception raised, returned \#{data_source} instead"
93
- rescue Exception => e
94
- puts e.class
95
- end
96
- end
97
- rescue Exception => e
98
- puts "Unexpected exception: \#{e}"
99
- end
100
- EOF
101
-
102
- assert_sub_process_returns(['TZInfo::DataSourceNotFound'], code)
103
- end
104
-
105
- def test_set_instance
106
- DataSource.set(DummyDataSource.new)
107
- data_source = DataSource.get
108
- assert_kind_of(DummyDataSource, data_source)
109
- end
110
-
111
- def test_set_standard_ruby
112
- DataSource.set(:ruby)
113
- data_source = DataSource.get
114
- assert_kind_of(RubyDataSource, data_source)
115
- end
116
-
117
- def test_set_standard_zoneinfo_search
118
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
119
- FileUtils.touch(File.join(dir, 'iso3166.tab'))
120
- FileUtils.touch(File.join(dir, 'zone.tab'))
121
-
122
- ZoneinfoDataSource.search_path = [dir]
123
-
124
- DataSource.set(:zoneinfo)
125
- data_source = DataSource.get
126
- assert_kind_of(ZoneinfoDataSource, data_source)
127
- assert_equal(dir, data_source.zoneinfo_dir)
128
- end
129
- end
130
-
131
- def test_set_standard_zoneinfo_search_zone1970
132
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
133
- FileUtils.touch(File.join(dir, 'iso3166.tab'))
134
- FileUtils.touch(File.join(dir, 'zone1970.tab'))
135
-
136
- ZoneinfoDataSource.search_path = [dir]
137
-
138
- DataSource.set(:zoneinfo)
139
- data_source = DataSource.get
140
- assert_kind_of(ZoneinfoDataSource, data_source)
141
- assert_equal(dir, data_source.zoneinfo_dir)
142
- end
143
- end
144
-
145
- def test_set_standard_zoneinfo_explicit
146
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
147
- FileUtils.touch(File.join(dir, 'iso3166.tab'))
148
- FileUtils.touch(File.join(dir, 'zone.tab'))
149
-
150
- DataSource.set(:zoneinfo, dir)
151
- data_source = DataSource.get
152
- assert_kind_of(ZoneinfoDataSource, data_source)
153
- assert_equal(dir, data_source.zoneinfo_dir)
154
- end
155
- end
156
-
157
- def test_set_standard_zoneinfo_explicit_zone1970
158
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
159
- FileUtils.touch(File.join(dir, 'iso3166.tab'))
160
- FileUtils.touch(File.join(dir, 'zone.tab'))
161
-
162
- DataSource.set(:zoneinfo, dir)
163
- data_source = DataSource.get
164
- assert_kind_of(ZoneinfoDataSource, data_source)
165
- assert_equal(dir, data_source.zoneinfo_dir)
166
- end
167
- end
168
-
169
- def test_set_standard_zoneinfo_explicit_alternate_iso3166
170
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
171
- zoneinfo_dir = File.join(dir, 'zoneinfo')
172
- tab_dir = File.join(dir, 'tab')
173
-
174
- FileUtils.mkdir(zoneinfo_dir)
175
- FileUtils.mkdir(tab_dir)
176
-
177
- FileUtils.touch(File.join(zoneinfo_dir, 'zone.tab'))
178
-
179
- iso3166_file = File.join(tab_dir, 'iso3166.tab')
180
- FileUtils.touch(iso3166_file)
181
-
182
- DataSource.set(:zoneinfo, zoneinfo_dir, iso3166_file)
183
- data_source = DataSource.get
184
- assert_kind_of(ZoneinfoDataSource, data_source)
185
- assert_equal(zoneinfo_dir, data_source.zoneinfo_dir)
186
- end
187
- end
188
-
189
- def test_set_standard_zoneinfo_search_not_found
190
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
191
- ZoneinfoDataSource.search_path = [dir]
192
-
193
- assert_raises(ZoneinfoDirectoryNotFound) do
194
- DataSource.set(:zoneinfo)
195
- end
196
-
197
- assert_kind_of(InitDataSource, DataSource.get)
198
- end
199
- end
200
-
201
- def test_set_standard_zoneinfo_explicit_invalid
202
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
203
- assert_raises(InvalidZoneinfoDirectory) do
204
- DataSource.set(:zoneinfo, dir)
205
- end
206
-
207
- assert_kind_of(InitDataSource, DataSource.get)
208
- end
209
- end
210
-
211
- def test_set_standard_zoneinfo_wrong_arg_count
212
- assert_raises(ArgumentError) do
213
- DataSource.set(:zoneinfo, 1, 2, 3)
214
- end
215
-
216
- assert_kind_of(InitDataSource, DataSource.get)
217
- end
218
- end