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
@@ -1,168 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
4
-
5
- include TZInfo
6
-
7
- class TCRubyCoreSupport < Minitest::Test
8
- def test_rational_new!
9
- assert_equal(Rational(3,4), RubyCoreSupport.rational_new!(3,4))
10
- end
11
-
12
- def test_datetime_new!
13
- assert_equal(DateTime.new(2008,10,5,12,0,0, 0, Date::ITALY), RubyCoreSupport.datetime_new!(2454745,0,2299161))
14
- assert_equal(DateTime.new(2008,10,5,13,0,0, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new!(2454745,Rational(1, 24),2299161))
15
-
16
- assert_equal(DateTime.new(2008,10,5,20,30,0, 0, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(117827777, 48), 0, 2299161))
17
- assert_equal(DateTime.new(2008,10,5,21,30,0, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new!(Rational(117827777, 48), Rational(1, 24), 2299161))
18
-
19
- assert_equal(DateTime.new(2008,10,6,6,26,21, 0, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(70696678127,28800), 0, 2299161))
20
- assert_equal(DateTime.new(2008,10,6,7,26,21, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new!(Rational(70696678127, 28800), Rational(1, 24), 2299161))
21
-
22
- assert_equal(DateTime.new(-4712,1,1,12,0,0, 0, Date::ITALY), RubyCoreSupport.datetime_new!(0, 0, 2299161))
23
- assert_equal(DateTime.new(-4712,1,1,13,0,0, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new!(0, Rational(1, 24), 2299161))
24
-
25
- assert_equal(DateTime.new(-4713,12,31,23,58,59, 0, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(-43261, 86400), 0, 2299161))
26
- assert_equal(DateTime.new(-4712,1,1,0,58,59, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new!(Rational(-43261, 86400), Rational(1, 24), 2299161))
27
-
28
- assert_equal(DateTime.new(-4713,12,30,23,58,59, 0, Date::ITALY), RubyCoreSupport.datetime_new!(Rational(-129661, 86400), 0, 2299161))
29
- assert_equal(DateTime.new(-4713,12,31,0,58,59, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new!(Rational(-129661, 86400), Rational(1, 24), 2299161))
30
- end
31
-
32
- def test_datetime_new
33
- assert_equal(DateTime.new(2012, 12, 31, 23, 59, 59, 0, Date::ITALY), RubyCoreSupport.datetime_new(2012, 12, 31, 23, 59, 59, 0, Date::ITALY))
34
- assert_equal(DateTime.new(2013, 2, 6, 23, 2, 36, Rational(1, 24), Date::ITALY), RubyCoreSupport.datetime_new(2013, 2, 6, 23, 2, 36, Rational(1,24), Date::ITALY))
35
-
36
- assert_equal(DateTime.new(2012, 12, 31, 23, 59, 59, 0, Date::ITALY) + Rational(1, 86400000), RubyCoreSupport.datetime_new(2012, 12, 31, 23, 59, 59 + Rational(1, 1000), 0, Date::ITALY))
37
- assert_equal(DateTime.new(2001, 10, 12, 12, 22, 59, Rational(1, 24), Date::ITALY) + Rational(501, 86400000), RubyCoreSupport.datetime_new(2001, 10, 12, 12, 22, 59 + Rational(501, 1000), Rational(1, 24), Date::ITALY))
38
- end
39
-
40
- def test_time_supports_negative
41
- if RubyCoreSupport.time_supports_negative
42
- assert_equal(Time.utc(1969, 12, 31, 23, 59, 59), Time.at(-1).utc)
43
- else
44
- assert_raises(ArgumentError) do
45
- Time.at(-1)
46
- end
47
- end
48
- end
49
-
50
- def test_time_supports_64_bit
51
- if RubyCoreSupport.time_supports_64bit
52
- assert_equal(Time.utc(1901, 12, 13, 20, 45, 51), Time.at(-2147483649).utc)
53
- assert_equal(Time.utc(2038, 1, 19, 3, 14, 8), Time.at(2147483648).utc)
54
- else
55
- assert_raises(RangeError) do
56
- Time.at(-2147483649)
57
- end
58
-
59
- assert_raises(RangeError) do
60
- Time.at(2147483648)
61
- end
62
- end
63
- end
64
-
65
- def test_time_nsec
66
- t = Time.utc(2013, 2, 6, 21, 56, 23, 567890 + Rational(123,1000))
67
-
68
- if t.respond_to?(:nsec)
69
- assert_equal(567890123, RubyCoreSupport.time_nsec(t))
70
- else
71
- assert_equal(567890000, RubyCoreSupport.time_nsec(t))
72
- end
73
- end
74
-
75
- def test_force_encoding
76
- s = [0xC2, 0xA9].pack('c2')
77
-
78
- if s.respond_to?(:force_encoding)
79
- # Ruby 1.9+ - should call String#force_encoding
80
- assert_equal('ASCII-8BIT', s.encoding.name)
81
- assert_equal(2, s.bytesize)
82
- result = RubyCoreSupport.force_encoding(s, 'UTF-8')
83
- assert_same(s, result)
84
- assert_equal('UTF-8', s.encoding.name)
85
- assert_equal(2, s.bytesize)
86
- assert_equal(1, s.length)
87
- assert_equal('©', s)
88
- else
89
- # Ruby 1.8 - no-op
90
- result = RubyCoreSupport.force_encoding(s, 'UTF-8')
91
- assert_same(s, result)
92
- assert_equal('©', s)
93
- end
94
- end
95
-
96
- begin
97
- SUPPORTS_ENCODING = !!Encoding
98
- rescue NameError
99
- SUPPORTS_ENCODING = false
100
- end
101
-
102
- def check_open_file_test_file_bytes(test_file)
103
- if SUPPORTS_ENCODING
104
- File.open(test_file, 'r') do |file|
105
- file.binmode
106
- data = file.read(2)
107
- refute_nil(data)
108
- assert_equal(2, data.length)
109
- bytes = data.unpack('C2')
110
- assert_equal(0xC2, bytes[0])
111
- assert_equal(0xA9, bytes[1])
112
- end
113
- end
114
- end
115
-
116
- def check_open_file_test_file_content(file)
117
- content = file.gets
118
- refute_nil(content)
119
- content.chomp!
120
-
121
- if SUPPORTS_ENCODING
122
- assert_equal('UTF-8', content.encoding.name)
123
- assert_equal(1, content.length)
124
- assert_equal(2, content.bytesize)
125
- assert_equal('©', content)
126
- else
127
- assert_equal('x', content)
128
- end
129
- end
130
-
131
- def test_open_file
132
- Dir.mktmpdir('tzinfo_test') do |dir|
133
- test_file = File.join(dir, 'test.txt')
134
-
135
- file = RubyCoreSupport.open_file(test_file, 'w', :external_encoding => 'UTF-8')
136
- begin
137
- file.puts(SUPPORTS_ENCODING ? '©' : 'x')
138
- ensure
139
- file.close
140
- end
141
-
142
- check_open_file_test_file_bytes(test_file)
143
-
144
- file = RubyCoreSupport.open_file(test_file, 'r', :external_encoding => 'UTF-8', :internal_encoding => 'UTF-8')
145
- begin
146
- check_open_file_test_file_content(file)
147
- ensure
148
- file.close
149
- end
150
- end
151
- end
152
-
153
- def test_open_file_block
154
- Dir.mktmpdir('tzinfo_test') do |dir|
155
- test_file = File.join(dir, 'test.txt')
156
-
157
- RubyCoreSupport.open_file(test_file, 'w', :external_encoding => 'UTF-8') do |file|
158
- file.puts(SUPPORTS_ENCODING ? '©' : 'x')
159
- end
160
-
161
- check_open_file_test_file_bytes(test_file)
162
-
163
- RubyCoreSupport.open_file(test_file, 'r', :external_encoding => 'UTF-8', :internal_encoding => 'UTF-8') do |file|
164
- check_open_file_test_file_content(file)
165
- end
166
- end
167
- end
168
- end
@@ -1,110 +0,0 @@
1
- require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
2
-
3
- include TZInfo
4
-
5
- class TCRubyCountryInfo < Minitest::Test
6
-
7
- def test_code
8
- ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
9
- assert_equal('ZZ', ci.code)
10
- end
11
-
12
- def test_name
13
- ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
14
- assert_equal('Zzz', ci.name)
15
- end
16
-
17
- def test_zone_identifiers_empty
18
- ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
19
- assert(ci.zone_identifiers.empty?)
20
- assert(ci.zone_identifiers.frozen?)
21
- end
22
-
23
- def test_zone_identifiers_no_block
24
- ci = RubyCountryInfo.new('ZZ', 'Zzz')
25
- assert(ci.zone_identifiers.empty?)
26
- assert(ci.zone_identifiers.frozen?)
27
- end
28
-
29
- def test_zone_identifiers
30
- ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
31
- c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
32
- c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
33
- c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
34
- c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
35
- end
36
-
37
- assert_equal(['ZZ/TimezoneB', 'ZZ/TimezoneA', 'ZZ/TimezoneC', 'ZZ/TimezoneD'], ci.zone_identifiers)
38
- assert(ci.zone_identifiers.frozen?)
39
- end
40
-
41
- def test_zone_identifiers_after_freeze
42
- ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
43
- c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
44
- c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
45
- c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
46
- c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
47
- end
48
-
49
- ci.freeze
50
-
51
- assert_equal(['ZZ/TimezoneB', 'ZZ/TimezoneA', 'ZZ/TimezoneC', 'ZZ/TimezoneD'], ci.zone_identifiers)
52
- end
53
-
54
- def test_zones_empty
55
- ci = RubyCountryInfo.new('ZZ', 'Zzz') {|c| }
56
- assert(ci.zones.empty?)
57
- assert(ci.zones.frozen?)
58
- end
59
-
60
- def test_zones_no_block
61
- ci = RubyCountryInfo.new('ZZ', 'Zzz')
62
- assert(ci.zones.empty?)
63
- assert(ci.zones.frozen?)
64
- end
65
-
66
- def test_zones
67
- ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
68
- c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
69
- c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
70
- c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
71
- c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
72
- end
73
-
74
- assert_equal([CountryTimezone.new!('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B'),
75
- CountryTimezone.new!('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A'),
76
- CountryTimezone.new!('ZZ/TimezoneC', -10, 3, -20, 7, 'C'),
77
- CountryTimezone.new!('ZZ/TimezoneD', -10, 3, -20, 7)],
78
- ci.zones)
79
- assert(ci.zones.frozen?)
80
- end
81
-
82
- def test_zones_after_freeze
83
- ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
84
- c.timezone('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B')
85
- c.timezone('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A')
86
- c.timezone('ZZ/TimezoneC', -10, 3, -20, 7, 'C')
87
- c.timezone('ZZ/TimezoneD', -10, 3, -20, 7)
88
- end
89
-
90
- ci.freeze
91
-
92
- assert_equal([CountryTimezone.new!('ZZ/TimezoneB', 1, 2, 1, 2, 'Timezone B'),
93
- CountryTimezone.new!('ZZ/TimezoneA', 1, 4, 1, 4, 'Timezone A'),
94
- CountryTimezone.new!('ZZ/TimezoneC', -10, 3, -20, 7, 'C'),
95
- CountryTimezone.new!('ZZ/TimezoneD', -10, 3, -20, 7)],
96
- ci.zones)
97
- end
98
-
99
- def test_deferred_evaluate
100
- block_called = false
101
-
102
- ci = RubyCountryInfo.new('ZZ', 'Zzz') do |c|
103
- block_called = true
104
- end
105
-
106
- assert_equal(false, block_called)
107
- ci.zones
108
- assert_equal(true, block_called)
109
- end
110
- end
@@ -1,173 +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 TCRubyDataSource < Minitest::Test
10
- def setup
11
- @data_source = RubyDataSource.new
12
- end
13
-
14
- def test_initialize_not_found
15
- # A failure to load tzinfo/data in initialize will not cause an exception.
16
- # Attempts to load data files will subsequently fail.
17
- code = <<-EOF
18
- begin
19
- ds = TZInfo::RubyDataSource.new
20
- puts 'Initialized'
21
- ds.load_timezone_info('Europe/London')
22
- rescue Exception => e
23
- puts e.class
24
- end
25
- EOF
26
-
27
- assert_sub_process_returns(['Initialized', 'TZInfo::InvalidTimezoneIdentifier'], code)
28
- end
29
-
30
- def test_load_timezone_info_data
31
- info = @data_source.load_timezone_info('Europe/London')
32
- assert_kind_of(DataTimezoneInfo, info)
33
- assert_equal('Europe/London', info.identifier)
34
- end
35
-
36
- def test_load_timezone_info_linked
37
- info = @data_source.load_timezone_info('UTC')
38
- assert_kind_of(LinkedTimezoneInfo, info)
39
- assert_equal('UTC', info.identifier)
40
- assert_equal('Etc/UTC', info.link_to_identifier)
41
- end
42
-
43
- def test_load_timezone_info_does_not_exist
44
- assert_raises(InvalidTimezoneIdentifier) do
45
- @data_source.load_timezone_info('Nowhere/Special')
46
- end
47
- end
48
-
49
- def test_load_timezone_info_invalid
50
- assert_raises(InvalidTimezoneIdentifier) do
51
- @data_source.load_timezone_info('../definitions/UTC')
52
- end
53
- end
54
-
55
- def test_load_timezone_info_directory_traversal
56
- test_data_depth = TZINFO_TEST_DATA_DIR.scan('/').size
57
- payload_path = File.join(TESTS_DIR, 'assets', 'payload')
58
- assert_raises(InvalidTimezoneIdentifier) { Timezone.get("foo\n#{'/..' * (test_data_depth + 4)}#{payload_path}") }
59
- end
60
-
61
- def test_load_timezone_info_nil
62
- assert_raises(InvalidTimezoneIdentifier) do
63
- @data_source.load_timezone_info(nil)
64
- end
65
- end
66
-
67
- def test_load_timezone_info_case
68
- assert_raises(InvalidTimezoneIdentifier) do
69
- @data_source.load_timezone_info('europe/london')
70
- end
71
- end
72
-
73
- def test_load_timezone_info_plus
74
- info = @data_source.load_timezone_info('Etc/GMT+1')
75
- assert_equal('Etc/GMT+1', info.identifier)
76
- end
77
-
78
- def test_load_timezone_info_minus
79
- info = @data_source.load_timezone_info('Etc/GMT-1')
80
- assert_equal('Etc/GMT-1', info.identifier)
81
- end
82
-
83
- def test_load_timezone_info_tainted
84
- skip_if_has_bug_14060
85
-
86
- safe_test(:unavailable => :skip) do
87
- identifier = 'Europe/Amsterdam'.dup.taint
88
- assert(identifier.tainted?)
89
- info = @data_source.load_timezone_info(identifier)
90
- assert_equal('Europe/Amsterdam', info.identifier)
91
- assert(identifier.tainted?)
92
- end
93
- end
94
-
95
- def test_load_timezone_info_tainted_and_frozen
96
- skip_if_has_bug_14060
97
-
98
- safe_test do
99
- info = @data_source.load_timezone_info('Europe/Amsterdam'.dup.taint.freeze)
100
- assert_equal('Europe/Amsterdam', info.identifier)
101
- end
102
- end
103
-
104
- def test_timezone_identifiers
105
- all = @data_source.timezone_identifiers
106
- assert_equal(TZInfo::Data::Indexes::Timezones.timezones, all)
107
- assert_equal(true, all.frozen?)
108
- end
109
-
110
- def test_data_timezone_identifiers
111
- all_data = @data_source.data_timezone_identifiers
112
- assert_equal(TZInfo::Data::Indexes::Timezones.data_timezones, all_data)
113
- assert_equal(true, all_data.frozen?)
114
- end
115
-
116
- def test_linked_timezone_identifiers
117
- all_linked = @data_source.linked_timezone_identifiers
118
- assert_equal(TZInfo::Data::Indexes::Timezones.linked_timezones, all_linked)
119
- assert_equal(true, all_linked.frozen?)
120
- end
121
-
122
- def test_load_country_info
123
- info = @data_source.load_country_info('GB')
124
- assert_equal('GB', info.code)
125
- end
126
-
127
- def test_load_country_info_not_exist
128
- assert_raises(InvalidCountryCode) do
129
- @data_source.load_country_info('ZZ')
130
- end
131
- end
132
-
133
- def test_load_country_info_invalid
134
- assert_raises(InvalidCountryCode) do
135
- @data_source.load_country_info('../Countries/GB')
136
- end
137
- end
138
-
139
- def test_load_country_info_nil
140
- assert_raises(InvalidCountryCode) do
141
- @data_source.load_country_info(nil)
142
- end
143
- end
144
-
145
- def test_load_country_info_case
146
- assert_raises(InvalidCountryCode) do
147
- @data_source.load_country_info('gb')
148
- end
149
- end
150
-
151
- def test_load_country_info_tainted
152
- safe_test(:unavailable => :skip) do
153
- code = 'NL'.dup.taint
154
- assert(code.tainted?)
155
- info = @data_source.load_country_info(code)
156
- assert_equal('NL', info.code)
157
- assert(code.tainted?)
158
- end
159
- end
160
-
161
- def test_load_country_info_tainted_and_frozen
162
- safe_test do
163
- info = @data_source.load_country_info('NL'.dup.taint.freeze)
164
- assert_equal('NL', info.code)
165
- end
166
- end
167
-
168
- def test_country_codes
169
- codes = @data_source.country_codes
170
- assert_equal(TZInfo::Data::Indexes::Countries.countries.keys, codes)
171
- assert_equal(true, codes.frozen?)
172
- end
173
- end