tzinfo 1.2.6 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +1 -1
  4. data/.yardopts +3 -0
  5. data/CHANGES.md +482 -380
  6. data/LICENSE +12 -12
  7. data/README.md +368 -114
  8. data/lib/tzinfo.rb +64 -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 +143 -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 +575 -0
  21. data/lib/tzinfo/data_sources/zoneinfo_reader.rb +286 -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 +43 -99
  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 -176
  63. data/lib/tzinfo/ruby_country_info.rb +0 -74
  64. data/lib/tzinfo/ruby_data_source.rb +0 -138
  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 -298
  74. data/test/tc_country.rb +0 -236
  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 -165
  88. data/test/tc_time_or_datetime.rb +0 -660
  89. data/test/tc_timezone.rb +0 -1359
  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 -1234
  106. data/test/test_utils.rb +0 -188
  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,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