tzinfo 1.2.9 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/.yardopts +3 -0
- data/CHANGES.md +589 -387
- data/LICENSE +13 -13
- data/README.md +368 -114
- data/lib/tzinfo/annual_rules.rb +32 -12
- data/lib/tzinfo/country.rb +141 -129
- data/lib/tzinfo/country_timezone.rb +70 -112
- data/lib/tzinfo/data_source.rb +400 -144
- data/lib/tzinfo/data_sources/constant_offset_data_timezone_info.rb +56 -0
- data/lib/tzinfo/data_sources/country_info.rb +42 -0
- data/lib/tzinfo/data_sources/data_timezone_info.rb +91 -0
- data/lib/tzinfo/data_sources/linked_timezone_info.rb +33 -0
- data/lib/tzinfo/data_sources/posix_time_zone_parser.rb +177 -0
- data/lib/tzinfo/data_sources/ruby_data_source.rb +141 -0
- data/lib/tzinfo/data_sources/timezone_info.rb +47 -0
- data/lib/tzinfo/data_sources/transitions_data_timezone_info.rb +214 -0
- data/lib/tzinfo/data_sources/zoneinfo_data_source.rb +592 -0
- data/lib/tzinfo/data_sources/zoneinfo_reader.rb +482 -0
- data/lib/tzinfo/data_sources.rb +8 -0
- data/lib/tzinfo/data_timezone.rb +33 -47
- data/lib/tzinfo/datetime_with_offset.rb +153 -0
- data/lib/tzinfo/format1/country_definer.rb +17 -0
- data/lib/tzinfo/format1/country_index_definition.rb +64 -0
- data/lib/tzinfo/format1/timezone_definer.rb +64 -0
- data/lib/tzinfo/format1/timezone_definition.rb +39 -0
- data/lib/tzinfo/format1/timezone_index_definition.rb +77 -0
- data/lib/tzinfo/format1.rb +10 -0
- data/lib/tzinfo/format2/country_definer.rb +68 -0
- data/lib/tzinfo/format2/country_index_definer.rb +68 -0
- data/lib/tzinfo/format2/country_index_definition.rb +46 -0
- data/lib/tzinfo/format2/timezone_definer.rb +94 -0
- data/lib/tzinfo/format2/timezone_definition.rb +73 -0
- data/lib/tzinfo/format2/timezone_index_definer.rb +45 -0
- data/lib/tzinfo/format2/timezone_index_definition.rb +55 -0
- data/lib/tzinfo/format2.rb +10 -0
- data/lib/tzinfo/info_timezone.rb +26 -21
- data/lib/tzinfo/linked_timezone.rb +33 -52
- data/lib/tzinfo/offset_timezone_period.rb +42 -0
- data/lib/tzinfo/ruby_core_support.rb +24 -155
- data/lib/tzinfo/string_deduper.rb +118 -0
- data/lib/tzinfo/time_with_offset.rb +154 -0
- data/lib/tzinfo/timestamp.rb +552 -0
- data/lib/tzinfo/timestamp_with_offset.rb +85 -0
- data/lib/tzinfo/timezone.rb +989 -502
- data/lib/tzinfo/timezone_offset.rb +84 -74
- data/lib/tzinfo/timezone_period.rb +151 -217
- data/lib/tzinfo/timezone_proxy.rb +70 -79
- data/lib/tzinfo/timezone_transition.rb +77 -109
- data/lib/tzinfo/transition_rule.rb +207 -77
- data/lib/tzinfo/transitions_timezone_period.rb +63 -0
- data/lib/tzinfo/version.rb +7 -0
- data/lib/tzinfo/with_offset.rb +61 -0
- data/lib/tzinfo.rb +78 -40
- data.tar.gz.sig +0 -0
- metadata +50 -104
- metadata.gz.sig +0 -0
- data/Rakefile +0 -107
- data/lib/tzinfo/country_index_definition.rb +0 -31
- data/lib/tzinfo/country_info.rb +0 -42
- data/lib/tzinfo/data_timezone_info.rb +0 -55
- data/lib/tzinfo/linked_timezone_info.rb +0 -26
- data/lib/tzinfo/offset_rationals.rb +0 -77
- data/lib/tzinfo/posix_time_zone_parser.rb +0 -136
- data/lib/tzinfo/ruby_country_info.rb +0 -74
- data/lib/tzinfo/ruby_data_source.rb +0 -140
- data/lib/tzinfo/time_or_datetime.rb +0 -351
- data/lib/tzinfo/timezone_definition.rb +0 -36
- data/lib/tzinfo/timezone_index_definition.rb +0 -54
- data/lib/tzinfo/timezone_info.rb +0 -30
- data/lib/tzinfo/timezone_transition_definition.rb +0 -104
- data/lib/tzinfo/transition_data_timezone_info.rb +0 -274
- data/lib/tzinfo/zoneinfo_country_info.rb +0 -37
- data/lib/tzinfo/zoneinfo_data_source.rb +0 -497
- data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -520
- data/test/tc_annual_rules.rb +0 -95
- data/test/tc_country.rb +0 -238
- data/test/tc_country_index_definition.rb +0 -69
- data/test/tc_country_info.rb +0 -16
- data/test/tc_country_timezone.rb +0 -173
- data/test/tc_data_source.rb +0 -218
- data/test/tc_data_timezone.rb +0 -99
- data/test/tc_data_timezone_info.rb +0 -18
- data/test/tc_info_timezone.rb +0 -34
- data/test/tc_linked_timezone.rb +0 -155
- data/test/tc_linked_timezone_info.rb +0 -23
- data/test/tc_offset_rationals.rb +0 -23
- data/test/tc_posix_time_zone_parser.rb +0 -261
- data/test/tc_ruby_core_support.rb +0 -168
- data/test/tc_ruby_country_info.rb +0 -110
- data/test/tc_ruby_data_source.rb +0 -167
- data/test/tc_time_or_datetime.rb +0 -674
- data/test/tc_timezone.rb +0 -1361
- data/test/tc_timezone_definition.rb +0 -113
- data/test/tc_timezone_index_definition.rb +0 -73
- data/test/tc_timezone_info.rb +0 -11
- data/test/tc_timezone_london.rb +0 -143
- data/test/tc_timezone_melbourne.rb +0 -142
- data/test/tc_timezone_new_york.rb +0 -142
- data/test/tc_timezone_offset.rb +0 -126
- data/test/tc_timezone_period.rb +0 -555
- data/test/tc_timezone_proxy.rb +0 -136
- data/test/tc_timezone_transition.rb +0 -366
- data/test/tc_timezone_transition_definition.rb +0 -295
- data/test/tc_timezone_utc.rb +0 -27
- data/test/tc_transition_data_timezone_info.rb +0 -433
- data/test/tc_transition_rule.rb +0 -663
- data/test/tc_zoneinfo_country_info.rb +0 -78
- data/test/tc_zoneinfo_data_source.rb +0 -1204
- data/test/tc_zoneinfo_timezone_info.rb +0 -2153
- data/test/test_utils.rb +0 -192
- data/test/ts_all.rb +0 -7
- data/test/ts_all_ruby.rb +0 -5
- data/test/ts_all_zoneinfo.rb +0 -9
- data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +0 -89
- data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +0 -327
- data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +0 -230
- data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +0 -19
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +0 -21
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +0 -21
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +0 -21
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +0 -273
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +0 -198
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +0 -333
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +0 -277
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +0 -235
- data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +0 -16
- data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +0 -940
- data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +0 -609
- data/test/tzinfo-data/tzinfo/data/version.rb +0 -20
- data/test/tzinfo-data/tzinfo/data.rb +0 -8
- data/test/zoneinfo/America/Argentina/Buenos_Aires +0 -0
- data/test/zoneinfo/America/New_York +0 -0
- data/test/zoneinfo/Australia/Melbourne +0 -0
- data/test/zoneinfo/EST +0 -0
- data/test/zoneinfo/Etc/UTC +0 -0
- data/test/zoneinfo/Europe/Amsterdam +0 -0
- data/test/zoneinfo/Europe/Andorra +0 -0
- data/test/zoneinfo/Europe/London +0 -0
- data/test/zoneinfo/Europe/Paris +0 -0
- data/test/zoneinfo/Europe/Prague +0 -0
- data/test/zoneinfo/Factory +0 -0
- data/test/zoneinfo/iso3166.tab +0 -274
- data/test/zoneinfo/leapseconds +0 -78
- data/test/zoneinfo/posix/Europe/London +0 -0
- data/test/zoneinfo/posixrules +0 -0
- data/test/zoneinfo/right/Europe/London +0 -0
- data/test/zoneinfo/zone.tab +0 -452
- data/test/zoneinfo/zone1970.tab +0 -384
- 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
|
data/test/tc_ruby_data_source.rb
DELETED
@@ -1,167 +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_nil
|
56
|
-
assert_raises(InvalidTimezoneIdentifier) do
|
57
|
-
@data_source.load_timezone_info(nil)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_load_timezone_info_case
|
62
|
-
assert_raises(InvalidTimezoneIdentifier) do
|
63
|
-
@data_source.load_timezone_info('europe/london')
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_load_timezone_info_plus
|
68
|
-
info = @data_source.load_timezone_info('Etc/GMT+1')
|
69
|
-
assert_equal('Etc/GMT+1', info.identifier)
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_load_timezone_info_minus
|
73
|
-
info = @data_source.load_timezone_info('Etc/GMT-1')
|
74
|
-
assert_equal('Etc/GMT-1', info.identifier)
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_load_timezone_info_tainted
|
78
|
-
skip_if_has_bug_14060
|
79
|
-
|
80
|
-
safe_test(:unavailable => :skip) do
|
81
|
-
identifier = 'Europe/Amsterdam'.dup.taint
|
82
|
-
assert(identifier.tainted?)
|
83
|
-
info = @data_source.load_timezone_info(identifier)
|
84
|
-
assert_equal('Europe/Amsterdam', info.identifier)
|
85
|
-
assert(identifier.tainted?)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_load_timezone_info_tainted_and_frozen
|
90
|
-
skip_if_has_bug_14060
|
91
|
-
|
92
|
-
safe_test do
|
93
|
-
info = @data_source.load_timezone_info('Europe/Amsterdam'.dup.taint.freeze)
|
94
|
-
assert_equal('Europe/Amsterdam', info.identifier)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_timezone_identifiers
|
99
|
-
all = @data_source.timezone_identifiers
|
100
|
-
assert_equal(TZInfo::Data::Indexes::Timezones.timezones, all)
|
101
|
-
assert_equal(true, all.frozen?)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_data_timezone_identifiers
|
105
|
-
all_data = @data_source.data_timezone_identifiers
|
106
|
-
assert_equal(TZInfo::Data::Indexes::Timezones.data_timezones, all_data)
|
107
|
-
assert_equal(true, all_data.frozen?)
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_linked_timezone_identifiers
|
111
|
-
all_linked = @data_source.linked_timezone_identifiers
|
112
|
-
assert_equal(TZInfo::Data::Indexes::Timezones.linked_timezones, all_linked)
|
113
|
-
assert_equal(true, all_linked.frozen?)
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_load_country_info
|
117
|
-
info = @data_source.load_country_info('GB')
|
118
|
-
assert_equal('GB', info.code)
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_load_country_info_not_exist
|
122
|
-
assert_raises(InvalidCountryCode) do
|
123
|
-
@data_source.load_country_info('ZZ')
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
def test_load_country_info_invalid
|
128
|
-
assert_raises(InvalidCountryCode) do
|
129
|
-
@data_source.load_country_info('../Countries/GB')
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_load_country_info_nil
|
134
|
-
assert_raises(InvalidCountryCode) do
|
135
|
-
@data_source.load_country_info(nil)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_load_country_info_case
|
140
|
-
assert_raises(InvalidCountryCode) do
|
141
|
-
@data_source.load_country_info('gb')
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_load_country_info_tainted
|
146
|
-
safe_test(:unavailable => :skip) do
|
147
|
-
code = 'NL'.dup.taint
|
148
|
-
assert(code.tainted?)
|
149
|
-
info = @data_source.load_country_info(code)
|
150
|
-
assert_equal('NL', info.code)
|
151
|
-
assert(code.tainted?)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_load_country_info_tainted_and_frozen
|
156
|
-
safe_test do
|
157
|
-
info = @data_source.load_country_info('NL'.dup.taint.freeze)
|
158
|
-
assert_equal('NL', info.code)
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
def test_country_codes
|
163
|
-
codes = @data_source.country_codes
|
164
|
-
assert_equal(TZInfo::Data::Indexes::Countries.countries.keys, codes)
|
165
|
-
assert_equal(true, codes.frozen?)
|
166
|
-
end
|
167
|
-
end
|