tzinfo 1.2.11 → 2.0.0
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 +469 -431
- data/LICENSE +13 -13
- data/README.md +368 -114
- data/lib/tzinfo/country.rb +131 -129
- data/lib/tzinfo/country_timezone.rb +70 -112
- data/lib/tzinfo/data_source.rb +389 -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/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 +573 -0
- data/lib/tzinfo/data_sources/zoneinfo_reader.rb +284 -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/string_deduper.rb +118 -0
- data/lib/tzinfo/time_with_offset.rb +128 -0
- data/lib/tzinfo/timestamp.rb +548 -0
- data/lib/tzinfo/timestamp_with_offset.rb +85 -0
- data/lib/tzinfo/timezone.rb +979 -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/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 +60 -40
- data.tar.gz.sig +0 -0
- metadata +51 -115
- metadata.gz.sig +2 -3
- data/Rakefile +0 -107
- data/lib/tzinfo/annual_rules.rb +0 -51
- 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_core_support.rb +0 -176
- data/lib/tzinfo/ruby_country_info.rb +0 -74
- data/lib/tzinfo/ruby_data_source.rb +0 -136
- 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/transition_rule.rb +0 -325
- data/lib/tzinfo/zoneinfo_country_info.rb +0 -37
- data/lib/tzinfo/zoneinfo_data_source.rb +0 -504
- data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -516
- data/test/assets/payload.rb +0 -1
- data/test/tc_annual_rules.rb +0 -95
- data/test/tc_country.rb +0 -240
- 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 -175
- 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 -1226
- data/test/tc_zoneinfo_timezone_info.rb +0 -2149
- data/test/test_utils.rb +0 -214
- 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
data/test/tc_data_source.rb
DELETED
@@ -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
|
data/test/tc_data_timezone.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
|
2
|
-
|
3
|
-
include TZInfo
|
4
|
-
|
5
|
-
class TCDataTimezone < Minitest::Test
|
6
|
-
|
7
|
-
class TestTimezoneInfo < TimezoneInfo
|
8
|
-
attr_reader :utc
|
9
|
-
attr_reader :local
|
10
|
-
attr_reader :utc_to
|
11
|
-
attr_reader :utc_from
|
12
|
-
|
13
|
-
def initialize(identifier, utc_period, local_periods, transitions_up_to)
|
14
|
-
super(identifier)
|
15
|
-
@utc_period = utc_period
|
16
|
-
@local_periods = local_periods || []
|
17
|
-
@transitions_up_to = transitions_up_to
|
18
|
-
end
|
19
|
-
|
20
|
-
def period_for_utc(utc)
|
21
|
-
@utc = utc
|
22
|
-
@utc_period
|
23
|
-
end
|
24
|
-
|
25
|
-
def periods_for_local(local)
|
26
|
-
@local = local
|
27
|
-
@local_periods
|
28
|
-
end
|
29
|
-
|
30
|
-
def transitions_up_to(utc_to, utc_from = nil)
|
31
|
-
@utc_to = utc_to
|
32
|
-
@utc_from = utc_from
|
33
|
-
@transitions_up_to
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_identifier
|
38
|
-
tz = DataTimezone.new(TestTimezoneInfo.new('Test/Zone', nil, [], []))
|
39
|
-
assert_equal('Test/Zone', tz.identifier)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_period_for_utc
|
43
|
-
# Don't need actual TimezonePeriods. DataTimezone isn't supposed to do
|
44
|
-
# anything with them apart from return them.
|
45
|
-
period = Object.new
|
46
|
-
tti = TestTimezoneInfo.new('Test/Zone', period, [], [])
|
47
|
-
tz = DataTimezone.new(tti)
|
48
|
-
|
49
|
-
t = Time.utc(2006, 6, 27, 22, 50, 12)
|
50
|
-
assert_same(period, tz.period_for_utc(t))
|
51
|
-
assert_same(t, tti.utc)
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_periods_for_local
|
55
|
-
# Don't need actual TimezonePeriods. DataTimezone isn't supposed to do
|
56
|
-
# anything with them apart from return them.
|
57
|
-
periods = [Object.new, Object.new]
|
58
|
-
tti = TestTimezoneInfo.new('Test/Zone', nil, periods, [])
|
59
|
-
tz = DataTimezone.new(tti)
|
60
|
-
|
61
|
-
t = Time.utc(2006, 6, 27, 22, 50, 12)
|
62
|
-
assert_same(periods, tz.periods_for_local(t))
|
63
|
-
assert_same(t, tti.local)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_periods_for_local_not_found
|
67
|
-
periods = []
|
68
|
-
tti = TestTimezoneInfo.new('Test/Zone', nil, periods, [])
|
69
|
-
tz = DataTimezone.new(tti)
|
70
|
-
|
71
|
-
t = Time.utc(2006, 6, 27, 22, 50, 12)
|
72
|
-
assert_same(periods, tz.periods_for_local(t))
|
73
|
-
assert_same(t, tti.local)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_transitions_up_to
|
77
|
-
# Don't need actual TimezoneTransition instances. DataTimezone isn't
|
78
|
-
# supposed to do anything with them apart from return them.
|
79
|
-
transitions = [Object.new, Object.new]
|
80
|
-
tti = TestTimezoneInfo.new('Test/Zone', nil, nil, transitions)
|
81
|
-
tz = DataTimezone.new(tti)
|
82
|
-
|
83
|
-
utc_to = Time.utc(2013, 1, 1, 0, 0, 0)
|
84
|
-
utc_from = Time.utc(2012, 1, 1, 0, 0, 0)
|
85
|
-
assert_same(transitions, tz.transitions_up_to(utc_to, utc_from))
|
86
|
-
assert_same(utc_to, tti.utc_to)
|
87
|
-
assert_same(utc_from, tti.utc_from)
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_canonical_identifier
|
91
|
-
tz = DataTimezone.new(TestTimezoneInfo.new('Test/Zone', nil, [], []))
|
92
|
-
assert_equal('Test/Zone', tz.canonical_identifier)
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_canonical_zone
|
96
|
-
tz = DataTimezone.new(TestTimezoneInfo.new('Test/Zone', nil, [], []))
|
97
|
-
assert_same(tz, tz.canonical_zone)
|
98
|
-
end
|
99
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
|
2
|
-
|
3
|
-
include TZInfo
|
4
|
-
|
5
|
-
class TCDataTimezoneInfo < Minitest::Test
|
6
|
-
|
7
|
-
def test_identifier
|
8
|
-
ti = DataTimezoneInfo.new('Test/Zone')
|
9
|
-
assert_equal('Test/Zone', ti.identifier)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_construct_timezone
|
13
|
-
ti = DataTimezoneInfo.new('Test/Zone')
|
14
|
-
tz = ti.create_timezone
|
15
|
-
assert_kind_of(DataTimezone, tz)
|
16
|
-
assert_equal('Test/Zone', tz.identifier)
|
17
|
-
end
|
18
|
-
end
|
data/test/tc_info_timezone.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
|
2
|
-
|
3
|
-
include TZInfo
|
4
|
-
|
5
|
-
class TCInfoTimezone < Minitest::Test
|
6
|
-
|
7
|
-
class TestInfoTimezone < InfoTimezone
|
8
|
-
attr_reader :setup_info
|
9
|
-
|
10
|
-
protected
|
11
|
-
def setup(info)
|
12
|
-
super(info)
|
13
|
-
@setup_info = info
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_identifier
|
18
|
-
tz = InfoTimezone.new(TimezoneInfo.new('Test/Identifier'))
|
19
|
-
assert_equal('Test/Identifier', tz.identifier)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_info
|
23
|
-
i = TimezoneInfo.new('Test/Identifier')
|
24
|
-
tz = InfoTimezone.new(i)
|
25
|
-
assert_same(i, tz.send(:info))
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_setup
|
29
|
-
i = TimezoneInfo.new('Test/Identifier')
|
30
|
-
tz = TestInfoTimezone.new(i)
|
31
|
-
assert_same(i, tz.setup_info)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
data/test/tc_linked_timezone.rb
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
|
2
|
-
|
3
|
-
include TZInfo
|
4
|
-
|
5
|
-
class TCLinkedTimezone < Minitest::Test
|
6
|
-
|
7
|
-
class TestTimezone < Timezone
|
8
|
-
attr_reader :utc_period
|
9
|
-
attr_reader :local_periods
|
10
|
-
attr_reader :up_to_transitions
|
11
|
-
attr_reader :utc
|
12
|
-
attr_reader :local
|
13
|
-
attr_reader :utc_to
|
14
|
-
attr_reader :utc_from
|
15
|
-
|
16
|
-
def self.new(identifier, no_local_periods = false)
|
17
|
-
tz = super()
|
18
|
-
tz.send(:setup, identifier, no_local_periods)
|
19
|
-
tz
|
20
|
-
end
|
21
|
-
|
22
|
-
def identifier
|
23
|
-
@identifier
|
24
|
-
end
|
25
|
-
|
26
|
-
def period_for_utc(utc)
|
27
|
-
@utc = utc
|
28
|
-
@utc_period
|
29
|
-
end
|
30
|
-
|
31
|
-
def periods_for_local(local)
|
32
|
-
@local = local
|
33
|
-
raise PeriodNotFound if @no_local_periods
|
34
|
-
@local_periods
|
35
|
-
end
|
36
|
-
|
37
|
-
def transitions_up_to(utc_to, utc_from = nil)
|
38
|
-
@utc_to = utc_to
|
39
|
-
@utc_from = utc_from
|
40
|
-
@up_to_transitions
|
41
|
-
end
|
42
|
-
|
43
|
-
def canonical_zone
|
44
|
-
self
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
def setup(identifier, no_local_periods)
|
49
|
-
@identifier = identifier
|
50
|
-
@no_local_periods = no_local_periods
|
51
|
-
|
52
|
-
# Don't have to be real TimezonePeriod or TimezoneTransition objects
|
53
|
-
# (nothing will use them).
|
54
|
-
@utc_period = Object.new
|
55
|
-
@local_periods = [Object.new, Object.new]
|
56
|
-
@up_to_transitions = [Object.new, Object.new]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
|
61
|
-
def setup
|
62
|
-
# Redefine Timezone.get to return a fake timezone.
|
63
|
-
# Use without_warnings to suppress redefined get method warning.
|
64
|
-
without_warnings do
|
65
|
-
def Timezone.get(identifier)
|
66
|
-
raise InvalidTimezoneIdentifier, 'Invalid identifier' if identifier == 'Invalid/Identifier'
|
67
|
-
|
68
|
-
@timezones ||= {}
|
69
|
-
@timezones[identifier] ||=
|
70
|
-
identifier == 'Test/Recursive/Linked' ?
|
71
|
-
LinkedTimezone.new(LinkedTimezoneInfo.new(identifier, 'Test/Recursive/Data')) :
|
72
|
-
TestTimezone.new(identifier, identifier == 'Test/No/Local')
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def teardown
|
78
|
-
# Re-require timezone to reset.
|
79
|
-
# Suppress redefined method warnings.
|
80
|
-
without_warnings do
|
81
|
-
load 'tzinfo/timezone.rb'
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_identifier
|
86
|
-
tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked'))
|
87
|
-
assert_equal('Test/Zone', tz.identifier)
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_invalid_linked_identifier
|
91
|
-
assert_raises(InvalidTimezoneIdentifier) { LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Invalid/Identifier')) }
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_period_for_utc
|
95
|
-
tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked'))
|
96
|
-
linked_tz = Timezone.get('Test/Linked')
|
97
|
-
t = Time.utc(2006, 6, 27, 23, 12, 28)
|
98
|
-
assert_same(linked_tz.utc_period, tz.period_for_utc(t))
|
99
|
-
assert_same(t, linked_tz.utc)
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_periods_for_local
|
103
|
-
tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked'))
|
104
|
-
linked_tz = Timezone.get('Test/Linked')
|
105
|
-
t = Time.utc(2006, 6, 27, 23, 12, 28)
|
106
|
-
assert_same(linked_tz.local_periods, tz.periods_for_local(t))
|
107
|
-
assert_same(t, linked_tz.local)
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_periods_for_local_not_found
|
111
|
-
tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/No/Local'))
|
112
|
-
linked_tz = Timezone.get('Test/No/Local')
|
113
|
-
t = Time.utc(2006, 6, 27, 23, 12, 28)
|
114
|
-
assert_raises(PeriodNotFound) { tz.periods_for_local(t) }
|
115
|
-
assert_same(t, linked_tz.local)
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_transitions_up_to
|
119
|
-
tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked'))
|
120
|
-
linked_tz = Timezone.get('Test/Linked')
|
121
|
-
utc_to = Time.utc(2013, 1, 1, 0, 0, 0)
|
122
|
-
utc_from = Time.utc(2012, 1, 1, 0, 0, 0)
|
123
|
-
assert_same(linked_tz.up_to_transitions, tz.transitions_up_to(utc_to, utc_from))
|
124
|
-
assert_same(utc_to, linked_tz.utc_to)
|
125
|
-
assert_same(utc_from, linked_tz.utc_from)
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_canonical_identifier
|
129
|
-
tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked'))
|
130
|
-
assert_equal('Test/Linked', tz.canonical_identifier)
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_canonical_identifier_recursive
|
134
|
-
# Recursive links are not currently used in the Time Zone database, but
|
135
|
-
# will be supported by TZInfo.
|
136
|
-
|
137
|
-
tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Recursive/Linked'))
|
138
|
-
assert_equal('Test/Recursive/Data', tz.canonical_identifier)
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_canonical_zone
|
142
|
-
tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked'))
|
143
|
-
linked_tz = Timezone.get('Test/Linked')
|
144
|
-
assert_same(linked_tz, tz.canonical_zone)
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_canonical_zone_recursive
|
148
|
-
# Recursive links are not currently used in the Time Zone database, but
|
149
|
-
# will be supported by TZInfo.
|
150
|
-
|
151
|
-
tz = LinkedTimezone.new(LinkedTimezoneInfo.new('Test/Zone', 'Test/Recursive/Linked'))
|
152
|
-
linked_tz = Timezone.get('Test/Recursive/Data')
|
153
|
-
assert_same(linked_tz, tz.canonical_zone)
|
154
|
-
end
|
155
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
|
2
|
-
|
3
|
-
include TZInfo
|
4
|
-
|
5
|
-
class TCLinkedTimezoneInfo < Minitest::Test
|
6
|
-
|
7
|
-
def test_identifier
|
8
|
-
lti = LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked')
|
9
|
-
assert_equal('Test/Zone', lti.identifier)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_link_to_identifier
|
13
|
-
lti = LinkedTimezoneInfo.new('Test/Zone', 'Test/Linked')
|
14
|
-
assert_equal('Test/Linked', lti.link_to_identifier)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_construct_timezone
|
18
|
-
lti = LinkedTimezoneInfo.new('Test/Zone', 'Europe/London')
|
19
|
-
tz = lti.create_timezone
|
20
|
-
assert_kind_of(LinkedTimezone, tz)
|
21
|
-
assert_equal('Test/Zone', tz.identifier)
|
22
|
-
end
|
23
|
-
end
|
data/test/tc_offset_rationals.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
|
2
|
-
|
3
|
-
include TZInfo
|
4
|
-
|
5
|
-
class TCOffsetRationals < Minitest::Test
|
6
|
-
def test_rational_for_offset
|
7
|
-
[0,1,2,3,4,-1,-2,-3,-4,30*60,-30*60,61*60,-61*60,14*60*60,-14*60*60,20*60*60,-20*60*60].each {|seconds|
|
8
|
-
assert_equal(Rational(seconds, 86400), OffsetRationals.rational_for_offset(seconds))
|
9
|
-
}
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_rational_for_offset_constant
|
13
|
-
-28.upto(28) {|i|
|
14
|
-
seconds = i * 30 * 60
|
15
|
-
|
16
|
-
r1 = OffsetRationals.rational_for_offset(seconds)
|
17
|
-
r2 = OffsetRationals.rational_for_offset(seconds)
|
18
|
-
|
19
|
-
assert_equal(Rational(seconds, 86400), r1)
|
20
|
-
assert_same(r1, r2)
|
21
|
-
}
|
22
|
-
end
|
23
|
-
end
|