tzinfo 1.2.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of tzinfo might be problematic. Click here for more details.

Files changed (111) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +3 -0
  3. data.tar.gz.sig +0 -0
  4. data/.yardopts +6 -0
  5. data/CHANGES.md +786 -0
  6. data/LICENSE +19 -0
  7. data/README.md +151 -0
  8. data/Rakefile +107 -0
  9. data/lib/tzinfo.rb +40 -0
  10. data/lib/tzinfo/country.rb +196 -0
  11. data/lib/tzinfo/country_index_definition.rb +31 -0
  12. data/lib/tzinfo/country_info.rb +42 -0
  13. data/lib/tzinfo/country_timezone.rb +135 -0
  14. data/lib/tzinfo/data_source.rb +190 -0
  15. data/lib/tzinfo/data_timezone.rb +58 -0
  16. data/lib/tzinfo/data_timezone_info.rb +55 -0
  17. data/lib/tzinfo/info_timezone.rb +30 -0
  18. data/lib/tzinfo/linked_timezone.rb +63 -0
  19. data/lib/tzinfo/linked_timezone_info.rb +26 -0
  20. data/lib/tzinfo/offset_rationals.rb +77 -0
  21. data/lib/tzinfo/ruby_core_support.rb +146 -0
  22. data/lib/tzinfo/ruby_country_info.rb +74 -0
  23. data/lib/tzinfo/ruby_data_source.rb +136 -0
  24. data/lib/tzinfo/time_or_datetime.rb +340 -0
  25. data/lib/tzinfo/timezone.rb +669 -0
  26. data/lib/tzinfo/timezone_definition.rb +36 -0
  27. data/lib/tzinfo/timezone_index_definition.rb +54 -0
  28. data/lib/tzinfo/timezone_info.rb +30 -0
  29. data/lib/tzinfo/timezone_offset.rb +101 -0
  30. data/lib/tzinfo/timezone_period.rb +245 -0
  31. data/lib/tzinfo/timezone_proxy.rb +105 -0
  32. data/lib/tzinfo/timezone_transition.rb +130 -0
  33. data/lib/tzinfo/timezone_transition_definition.rb +104 -0
  34. data/lib/tzinfo/transition_data_timezone_info.rb +274 -0
  35. data/lib/tzinfo/zoneinfo_country_info.rb +37 -0
  36. data/lib/tzinfo/zoneinfo_data_source.rb +488 -0
  37. data/lib/tzinfo/zoneinfo_timezone_info.rb +296 -0
  38. data/test/tc_country.rb +234 -0
  39. data/test/tc_country_index_definition.rb +69 -0
  40. data/test/tc_country_info.rb +16 -0
  41. data/test/tc_country_timezone.rb +173 -0
  42. data/test/tc_data_source.rb +218 -0
  43. data/test/tc_data_timezone.rb +99 -0
  44. data/test/tc_data_timezone_info.rb +18 -0
  45. data/test/tc_info_timezone.rb +34 -0
  46. data/test/tc_linked_timezone.rb +155 -0
  47. data/test/tc_linked_timezone_info.rb +23 -0
  48. data/test/tc_offset_rationals.rb +23 -0
  49. data/test/tc_ruby_core_support.rb +168 -0
  50. data/test/tc_ruby_country_info.rb +110 -0
  51. data/test/tc_ruby_data_source.rb +143 -0
  52. data/test/tc_time_or_datetime.rb +654 -0
  53. data/test/tc_timezone.rb +1350 -0
  54. data/test/tc_timezone_definition.rb +113 -0
  55. data/test/tc_timezone_index_definition.rb +73 -0
  56. data/test/tc_timezone_info.rb +11 -0
  57. data/test/tc_timezone_london.rb +143 -0
  58. data/test/tc_timezone_melbourne.rb +142 -0
  59. data/test/tc_timezone_new_york.rb +142 -0
  60. data/test/tc_timezone_offset.rb +126 -0
  61. data/test/tc_timezone_period.rb +555 -0
  62. data/test/tc_timezone_proxy.rb +136 -0
  63. data/test/tc_timezone_transition.rb +366 -0
  64. data/test/tc_timezone_transition_definition.rb +295 -0
  65. data/test/tc_timezone_utc.rb +27 -0
  66. data/test/tc_transition_data_timezone_info.rb +423 -0
  67. data/test/tc_zoneinfo_country_info.rb +78 -0
  68. data/test/tc_zoneinfo_data_source.rb +1195 -0
  69. data/test/tc_zoneinfo_timezone_info.rb +1232 -0
  70. data/test/test_utils.rb +163 -0
  71. data/test/ts_all.rb +7 -0
  72. data/test/ts_all_ruby.rb +5 -0
  73. data/test/ts_all_zoneinfo.rb +7 -0
  74. data/test/tzinfo-data/tzinfo/data.rb +8 -0
  75. data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +89 -0
  76. data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +315 -0
  77. data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +218 -0
  78. data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +19 -0
  79. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +21 -0
  80. data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +21 -0
  81. data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +21 -0
  82. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +261 -0
  83. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +186 -0
  84. data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +321 -0
  85. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +265 -0
  86. data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +220 -0
  87. data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +16 -0
  88. data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +927 -0
  89. data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +596 -0
  90. data/test/tzinfo-data/tzinfo/data/version.rb +14 -0
  91. data/test/zoneinfo/America/Argentina/Buenos_Aires +0 -0
  92. data/test/zoneinfo/America/New_York +0 -0
  93. data/test/zoneinfo/Australia/Melbourne +0 -0
  94. data/test/zoneinfo/EST +0 -0
  95. data/test/zoneinfo/Etc/UTC +0 -0
  96. data/test/zoneinfo/Europe/Amsterdam +0 -0
  97. data/test/zoneinfo/Europe/Andorra +0 -0
  98. data/test/zoneinfo/Europe/London +0 -0
  99. data/test/zoneinfo/Europe/Paris +0 -0
  100. data/test/zoneinfo/Europe/Prague +0 -0
  101. data/test/zoneinfo/Factory +0 -0
  102. data/test/zoneinfo/iso3166.tab +275 -0
  103. data/test/zoneinfo/leapseconds +61 -0
  104. data/test/zoneinfo/posix/Europe/London +0 -0
  105. data/test/zoneinfo/posixrules +0 -0
  106. data/test/zoneinfo/right/Europe/London +0 -0
  107. data/test/zoneinfo/zone.tab +439 -0
  108. data/test/zoneinfo/zone1970.tab +369 -0
  109. data/tzinfo.gemspec +21 -0
  110. metadata +193 -0
  111. metadata.gz.sig +2 -0
@@ -0,0 +1,69 @@
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
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,173 @@
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
@@ -0,0 +1,218 @@
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