tzinfo 1.2.1 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/.yardopts +3 -0
  4. data/CHANGES.md +693 -315
  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 +148 -120
  9. data/lib/tzinfo/country_timezone.rb +71 -101
  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 +997 -473
  46. data/lib/tzinfo/timezone_offset.rb +91 -54
  47. data/lib/tzinfo/timezone_period.rb +163 -188
  48. data/lib/tzinfo/timezone_proxy.rb +75 -49
  49. data/lib/tzinfo/timezone_transition.rb +77 -99
  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 -120
  58. metadata.gz.sig +0 -0
  59. data/Rakefile +0 -104
  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 -70
  67. data/lib/tzinfo/ruby_data_source.rb +0 -136
  68. data/lib/tzinfo/time_or_datetime.rb +0 -333
  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 -101
  73. data/lib/tzinfo/transition_data_timezone_info.rb +0 -274
  74. data/lib/tzinfo/zoneinfo_country_info.rb +0 -35
  75. data/lib/tzinfo/zoneinfo_data_source.rb +0 -460
  76. data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -245
  77. data/test/tc_country.rb +0 -236
  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 -161
  81. data/test/tc_data_source.rb +0 -192
  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 -80
  90. data/test/tc_ruby_data_source.rb +0 -143
  91. data/test/tc_time_or_datetime.rb +0 -639
  92. data/test/tc_timezone.rb +0 -1334
  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 -548
  101. data/test/tc_timezone_proxy.rb +0 -113
  102. data/test/tc_timezone_transition.rb +0 -352
  103. data/test/tc_timezone_transition_definition.rb +0 -284
  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 -64
  107. data/test/tc_zoneinfo_data_source.rb +0 -985
  108. data/test/tc_zoneinfo_timezone_info.rb +0 -814
  109. data/test/test_utils.rb +0 -132
  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 -594
  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/posix/Europe/London +0 -0
  143. data/test/zoneinfo/posixrules +0 -0
  144. data/test/zoneinfo/right/Europe/London +0 -0
  145. data/test/zoneinfo/zone.tab +0 -452
  146. data/tzinfo.gemspec +0 -21
data/test/tc_country.rb DELETED
@@ -1,236 +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'.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'.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'.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'.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
- c = Country.get('US')
194
- assert_equal('US', Country.get('US').code)
195
-
196
- # Suppress redefined method warnings.
197
- without_warnings do
198
- load 'tzinfo/country.rb'
199
- end
200
-
201
- c = Country.get('US')
202
- assert_equal('US', Country.get('US').code)
203
- end
204
-
205
- def test_get_missing_data_source
206
- DataSource.set(DataSource.new)
207
-
208
- assert_raises(InvalidDataSource) do
209
- Country.get('GB')
210
- end
211
- end
212
-
213
- def test_new_missing_data_source
214
- DataSource.set(DataSource.new)
215
-
216
- assert_raises(InvalidDataSource) do
217
- Country.new('GB')
218
- end
219
- end
220
-
221
- def test_all_codes_missing_data_source
222
- DataSource.set(DataSource.new)
223
-
224
- assert_raises(InvalidDataSource) do
225
- Country.all_codes
226
- end
227
- end
228
-
229
- def test_all_missing_data_source
230
- DataSource.set(DataSource.new)
231
-
232
- assert_raises(InvalidDataSource) do
233
- Country.all
234
- end
235
- end
236
- 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,161 +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_new
22
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
23
- assert_equal(Rational(2059, 40), ct.latitude)
24
- end
25
-
26
- def test_longitude_new!
27
- ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
28
- assert_equal(Rational(-5, 16), ct.longitude)
29
- end
30
-
31
- def test_longitude_new
32
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
33
- assert_equal(Rational(-5, 16), ct.longitude)
34
- end
35
-
36
- def test_description_omit_new!
37
- ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
38
- assert_nil(ct.description)
39
- end
40
-
41
- def test_description_omit_new
42
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
43
- assert_nil(ct.description)
44
- end
45
-
46
- def test_description_nil_new!
47
- ct = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16, nil)
48
- assert_nil(ct.description)
49
- end
50
-
51
- def test_description_nil_new
52
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16), nil)
53
- assert_nil(ct.description)
54
- end
55
-
56
- def test_description_new!
57
- ct = CountryTimezone.new!('America/New_York', 48857, 1200, -266423, 3600, 'Eastern Time')
58
- assert_equal('Eastern Time', ct.description)
59
- end
60
-
61
- def test_description_new
62
- ct = CountryTimezone.new('America/New_York', Rational(48857, 1200), Rational(-266423, 3600), 'Eastern Time')
63
- assert_equal('Eastern Time', ct.description)
64
- end
65
-
66
- def test_timezone
67
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
68
- assert_kind_of(TimezoneProxy, ct.timezone)
69
- assert_equal('Europe/London', ct.timezone.identifier)
70
- end
71
-
72
- def test_description_or_friendly_idenfier_no_description
73
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
74
- assert_equal('London', ct.description_or_friendly_identifier)
75
- end
76
-
77
- def test_description_or_friendly_idenfier_description
78
- ct = CountryTimezone.new('America/New_York', Rational(48857, 1200), Rational(-266423, 3600), 'Eastern Time')
79
- assert_equal('Eastern Time', ct.description_or_friendly_identifier)
80
- end
81
-
82
- def test_equality_1
83
- ct1 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
84
- ct2 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
85
- ct3 = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
86
- ct4 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16, 'Description')
87
- ct5 = CountryTimezone.new!('Europe/LondonB', 2059, 40, -5, 16)
88
- ct6 = CountryTimezone.new!('Europe/London', 2060, 40, -5, 16)
89
- ct7 = CountryTimezone.new!('Europe/London', 2059, 40, -6, 16)
90
-
91
- assert_equal(true, ct1 == ct1)
92
- assert_equal(true, ct1 == ct2)
93
- assert_equal(true, ct1 == ct3)
94
- assert_equal(false, ct1 == ct4)
95
- assert_equal(false, ct1 == ct5)
96
- assert_equal(false, ct1 == ct6)
97
- assert_equal(false, ct1 == ct7)
98
- end
99
-
100
- def test_equality_2
101
- ct1 = CountryTimezone.new!('America/New_York', 48857, 1200, -266423, 3600, 'Eastern Time')
102
- ct2 = CountryTimezone.new!('America/New_York', 48857, 1200, -266423, 3600, 'Eastern Time2')
103
-
104
- assert_equal(true, ct1 == ct1)
105
- assert_equal(false, ct1 == ct2)
106
- end
107
-
108
- def test_equality_non_country_timezone
109
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
110
-
111
- assert_equal(false, ct == Object.new)
112
- end
113
-
114
- def test_eql_1
115
- ct1 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
116
- ct2 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
117
- ct3 = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
118
- ct4 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16, 'Description')
119
- ct5 = CountryTimezone.new!('Europe/LondonB', 2059, 40, -5, 16)
120
- ct6 = CountryTimezone.new!('Europe/London', 2060, 40, -5, 16)
121
- ct7 = CountryTimezone.new!('Europe/London', 2059, 40, -6, 16)
122
-
123
- assert_equal(true, ct1.eql?(ct1))
124
- assert_equal(true, ct1.eql?(ct2))
125
- assert_equal(true, ct1.eql?(ct3))
126
- assert_equal(false, ct1.eql?(ct4))
127
- assert_equal(false, ct1.eql?(ct5))
128
- assert_equal(false, ct1.eql?(ct6))
129
- assert_equal(false, ct1.eql?(ct7))
130
- end
131
-
132
- def test_eql_2
133
- ct1 = CountryTimezone.new!('America/New_York', 48857, 1200, -266423, 3600, 'Eastern Time')
134
- ct2 = CountryTimezone.new!('America/New_York', 48857, 1200, -266423, 3600, 'Eastern Time2')
135
-
136
- assert_equal(true, ct1.eql?(ct1))
137
- assert_equal(false, ct1.eql?(ct2))
138
- end
139
-
140
- def test_eql_non_country_timezone
141
- ct = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
142
-
143
- assert_equal(false, ct.eql?(Object.new))
144
- end
145
-
146
- def test_hash_new!
147
- ct1 = CountryTimezone.new!('Europe/London', 2059, 40, -5, 16)
148
- ct2 = CountryTimezone.new!('America/New_York', 48857, 1200, -266423, 3600, 'Eastern Time')
149
-
150
- assert_equal('Europe/London'.hash ^ 2059.hash ^ 40.hash ^ -5.hash ^ 16.hash ^ nil.hash, ct1.hash)
151
- assert_equal('America/New_York'.hash ^ 48857.hash ^ 1200.hash ^ -266423.hash ^ 3600.hash ^ 'Eastern Time'.hash, ct2.hash)
152
- end
153
-
154
- def test_hash_new
155
- ct1 = CountryTimezone.new('Europe/London', Rational(2059, 40), Rational(-5, 16))
156
- ct2 = CountryTimezone.new('America/New_York', Rational(48857, 1200), Rational(-266423, 3600), 'Eastern Time')
157
-
158
- assert_equal('Europe/London'.hash ^ 2059.hash ^ 40.hash ^ -5.hash ^ 16.hash ^ nil.hash, ct1.hash)
159
- assert_equal('America/New_York'.hash ^ 48857.hash ^ 1200.hash ^ -266423.hash ^ 3600.hash ^ 'Eastern Time'.hash, ct2.hash)
160
- end
161
- end
@@ -1,192 +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_explicit
132
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
133
- FileUtils.touch(File.join(dir, 'iso3166.tab'))
134
- FileUtils.touch(File.join(dir, 'zone.tab'))
135
-
136
- DataSource.set(:zoneinfo, dir)
137
- data_source = DataSource.get
138
- assert_kind_of(ZoneinfoDataSource, data_source)
139
- assert_equal(dir, data_source.zoneinfo_dir)
140
- end
141
- end
142
-
143
- def test_set_standard_zoneinfo_explicit_alternate_iso3166
144
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
145
- zoneinfo_dir = File.join(dir, 'zoneinfo')
146
- tab_dir = File.join(dir, 'tab')
147
-
148
- FileUtils.mkdir(zoneinfo_dir)
149
- FileUtils.mkdir(tab_dir)
150
-
151
- FileUtils.touch(File.join(zoneinfo_dir, 'zone.tab'))
152
-
153
- iso3166_file = File.join(tab_dir, 'iso3166.tab')
154
- FileUtils.touch(iso3166_file)
155
-
156
- DataSource.set(:zoneinfo, zoneinfo_dir, iso3166_file)
157
- data_source = DataSource.get
158
- assert_kind_of(ZoneinfoDataSource, data_source)
159
- assert_equal(zoneinfo_dir, data_source.zoneinfo_dir)
160
- end
161
- end
162
-
163
- def test_set_standard_zoneinfo_search_not_found
164
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
165
- ZoneinfoDataSource.search_path = [dir]
166
-
167
- assert_raises(ZoneinfoDirectoryNotFound) do
168
- DataSource.set(:zoneinfo)
169
- end
170
-
171
- assert_kind_of(InitDataSource, DataSource.get)
172
- end
173
- end
174
-
175
- def test_set_standard_zoneinfo_explicit_invalid
176
- Dir.mktmpdir('tzinfo_test_dir') do |dir|
177
- assert_raises(InvalidZoneinfoDirectory) do
178
- DataSource.set(:zoneinfo, dir)
179
- end
180
-
181
- assert_kind_of(InitDataSource, DataSource.get)
182
- end
183
- end
184
-
185
- def test_set_standard_zoneinfo_wrong_arg_count
186
- assert_raises(ArgumentError) do
187
- DataSource.set(:zoneinfo, 1, 2, 3)
188
- end
189
-
190
- assert_kind_of(InitDataSource, DataSource.get)
191
- end
192
- end