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
@@ -1,261 +0,0 @@
|
|
1
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
|
2
|
-
|
3
|
-
include TZInfo
|
4
|
-
|
5
|
-
class TCPosixTimeZoneParser < Minitest::Test
|
6
|
-
HOUR = 3600
|
7
|
-
MINUTE = 60
|
8
|
-
|
9
|
-
class << self
|
10
|
-
private
|
11
|
-
|
12
|
-
def append_time_to_rule(day_rule, time)
|
13
|
-
time ? "#{day_rule}/#{time}" : day_rule
|
14
|
-
end
|
15
|
-
|
16
|
-
def define_invalid_dst_rule_tests(type, rule)
|
17
|
-
define_method "test_#{type}_dst_start_rule_for_invalid_#{rule}" do
|
18
|
-
tz_string = "STD-1DST,#{rule},300"
|
19
|
-
assert_raises(InvalidPosixTimeZone) { @parser.parse(tz_string) }
|
20
|
-
end
|
21
|
-
|
22
|
-
define_method "test_#{type}_dst_end_rule_for_invalid_#{rule}" do
|
23
|
-
tz_string = "STD-1DST,60,#{rule}"
|
24
|
-
assert_raises(InvalidPosixTimeZone) { @parser.parse(tz_string) }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def setup
|
30
|
-
@parser = PosixTimeZoneParser.new
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_empty_rule_returns_nil
|
34
|
-
result = @parser.parse('')
|
35
|
-
assert_nil(result)
|
36
|
-
end
|
37
|
-
|
38
|
-
ABBREVIATIONS_WITH_OFFSETS = [
|
39
|
-
['UTC0', :UTC, 0],
|
40
|
-
['U0', :U, 0],
|
41
|
-
['West1', :West, -HOUR],
|
42
|
-
['East-1', :East, HOUR],
|
43
|
-
['<-05>5', :'-05', -5 * HOUR],
|
44
|
-
['<+12>-12', :'+12', 12 * HOUR],
|
45
|
-
['HMM2:30', :HMM, -(2 * HOUR + 30 * MINUTE)],
|
46
|
-
['HHMM02:30', :HHMM, -(2 * HOUR + 30 * MINUTE)],
|
47
|
-
['HHMM+02:30', :HHMM, -(2 * HOUR + 30 * MINUTE)],
|
48
|
-
['HHMSS-12:5:50', :HHMSS, 12 * HOUR + 5 * MINUTE + 50],
|
49
|
-
['HHMMSS-12:05:50', :HHMMSS, 12 * HOUR + 5 * MINUTE + 50],
|
50
|
-
['HHMMS-12:05:7', :HHMMS, 12 * HOUR + 5 * MINUTE + 7]
|
51
|
-
]
|
52
|
-
|
53
|
-
ABBREVIATIONS_WITH_OFFSETS.each do |(tz_string, expected_abbrev, expected_base_offset)|
|
54
|
-
define_method "test_std_only_returns_std_offset_#{tz_string}" do
|
55
|
-
result = @parser.parse(tz_string)
|
56
|
-
expected = TimezoneOffset.new(expected_base_offset, 0, expected_abbrev)
|
57
|
-
assert_equal(expected, result)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
ABBREVIATIONS_WITH_OFFSETS.each do |(abbrev_and_offset, expected_abbrev, expected_base_offset)|
|
62
|
-
define_method "test_std_offset_#{abbrev_and_offset}" do
|
63
|
-
result = @parser.parse(abbrev_and_offset + 'DST,60,300')
|
64
|
-
expected_std_offset = TimezoneOffset.new(expected_base_offset, 0, expected_abbrev)
|
65
|
-
assert_equal(expected_std_offset, result.std_offset)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
[
|
70
|
-
['Zero0One-1', :One, 0, HOUR],
|
71
|
-
['Zero0One', :One, 0, HOUR],
|
72
|
-
['Z0O', :O, 0, HOUR],
|
73
|
-
['West1WestS0', :WestS, -HOUR, HOUR],
|
74
|
-
['West1WestS', :WestS, -HOUR, HOUR],
|
75
|
-
['East-1EastS-2', :EastS, HOUR, HOUR],
|
76
|
-
['East-1EastS', :EastS, HOUR, HOUR],
|
77
|
-
['Neg2NegS3', :NegS, -2 * HOUR, -HOUR],
|
78
|
-
['<-05>5<-04>4', :'-04', -5 * HOUR, HOUR],
|
79
|
-
['STD5<-04>4', :'-04', -5 * HOUR, HOUR],
|
80
|
-
['<+12>-12<+13>-13', :'+13', 12 * HOUR, HOUR],
|
81
|
-
['STD-12<+13>-13', :'+13', 12 * HOUR, HOUR],
|
82
|
-
['HMM2:30SHMM1:15', :SHMM, -(2 * HOUR + 30 * MINUTE), HOUR + 15 * MINUTE],
|
83
|
-
['HHMM02:30SHHMM01:15', :SHHMM, -(2 * HOUR + 30 * MINUTE), HOUR + 15 * MINUTE],
|
84
|
-
['HHMM+02:30SHHMM+01:15', :SHHMM, -(2 * HOUR + 30 * MINUTE), HOUR + 15 * MINUTE],
|
85
|
-
['HHMSS-12:5:50SHHMSS-13:4:30', :SHHMSS, 12 * HOUR + 5 * MINUTE + 50, 58 * MINUTE + 40],
|
86
|
-
['HHMMSS-12:05:50SHHMMSS-13:04:30', :SHHMMSS, 12 * HOUR + 5 * MINUTE + 50, 58 * MINUTE + 40],
|
87
|
-
['HHMMS-12:05:7SHHMMSS-13:06:8', :SHHMMSS, 12 * HOUR + 5 * MINUTE + 7, HOUR + MINUTE + 1],
|
88
|
-
].each do |(abbrevs_and_offsets, expected_abbrev, expected_base_offset, expected_std_offset)|
|
89
|
-
define_method "test_dst_offset_#{abbrevs_and_offsets}" do
|
90
|
-
result = @parser.parse(abbrevs_and_offsets + ',60,300')
|
91
|
-
expected_dst_offset = TimezoneOffset.new(expected_base_offset, expected_std_offset, expected_abbrev)
|
92
|
-
assert_equal(expected_dst_offset, result.dst_offset)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
['<M-1>01:-1', '<M60>01:60', '<S-1>01:00:-1', '<S60>01:00:60'].each do |abbrev_and_offset|
|
97
|
-
['', 'DST,60,300'].each do |dst_suffix|
|
98
|
-
tz_string = abbrev_and_offset + dst_suffix
|
99
|
-
define_method "test_std_offset_invalid_#{tz_string}" do
|
100
|
-
assert_raises(InvalidPosixTimeZone) { @parser.parse(tz_string) }
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
tz_string = "STD1#{abbrev_and_offset},60,300"
|
105
|
-
define_method "test_dst_offset_invalid_#{tz_string}" do
|
106
|
-
assert_raises(InvalidPosixTimeZone) { @parser.parse(tz_string) }
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
[
|
111
|
-
[nil, 2 * HOUR],
|
112
|
-
['2', 2 * HOUR],
|
113
|
-
['+2', 2 * HOUR],
|
114
|
-
['-2', -2 * HOUR],
|
115
|
-
['2:3:4', 2 * HOUR + 3 * MINUTE + 4],
|
116
|
-
['02:03:04', 2 * HOUR + 3 * MINUTE + 4],
|
117
|
-
['-2:3:4', -2 * HOUR + 3 * MINUTE + 4], # 22:03:04 on the day prior to the one specified
|
118
|
-
['-02:03:04', -2 * HOUR + 3 * MINUTE + 4],
|
119
|
-
['167', 167 * HOUR],
|
120
|
-
['-167', -167 * HOUR]
|
121
|
-
].each do |(time, expected_offset_from_midnight)|
|
122
|
-
[
|
123
|
-
['J1', 1],
|
124
|
-
['J365', 365]
|
125
|
-
].each do |(julian_day_rule, expected_julian_day)|
|
126
|
-
rule = append_time_to_rule(julian_day_rule, time)
|
127
|
-
|
128
|
-
define_method "test_julian_day_dst_start_rule_for_#{rule}" do
|
129
|
-
result = @parser.parse("STD-1DST,#{rule},300")
|
130
|
-
expected_dst_start_rule = JulianDayOfYearTransitionRule.new(expected_julian_day, expected_offset_from_midnight)
|
131
|
-
assert_equal(expected_dst_start_rule, result.dst_start_rule)
|
132
|
-
end
|
133
|
-
|
134
|
-
define_method "test_julian_day_dst_end_rule_for_#{rule}" do
|
135
|
-
result = @parser.parse("STD-1DST,60,#{rule}")
|
136
|
-
expected_dst_end_rule = JulianDayOfYearTransitionRule.new(expected_julian_day, expected_offset_from_midnight)
|
137
|
-
assert_equal(expected_dst_end_rule, result.dst_end_rule)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
[
|
142
|
-
['0', 0],
|
143
|
-
['365', 365]
|
144
|
-
].each do |(absolute_day_rule, expected_day)|
|
145
|
-
rule = append_time_to_rule(absolute_day_rule, time)
|
146
|
-
|
147
|
-
define_method "test_absolute_day_dst_start_rule_for_#{rule}" do
|
148
|
-
result = @parser.parse("STD-1DST,#{rule},J300")
|
149
|
-
expected_dst_start_rule = AbsoluteDayOfYearTransitionRule.new(expected_day, expected_offset_from_midnight)
|
150
|
-
assert_equal(expected_dst_start_rule, result.dst_start_rule)
|
151
|
-
end
|
152
|
-
|
153
|
-
define_method "test_absolute_day_dst_end_rule_for_#{rule}" do
|
154
|
-
result = @parser.parse("STD-1DST,J60,#{rule}")
|
155
|
-
expected_dst_end_rule = AbsoluteDayOfYearTransitionRule.new(expected_day, expected_offset_from_midnight)
|
156
|
-
assert_equal(expected_dst_end_rule, result.dst_end_rule)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
[
|
161
|
-
['M1.1.0', 1, 1, 0],
|
162
|
-
['M12.4.6', 12, 4, 6]
|
163
|
-
].each do |(day_of_month_rule, expected_month, expected_week, expected_day_of_week)|
|
164
|
-
rule = append_time_to_rule(day_of_month_rule, time)
|
165
|
-
|
166
|
-
define_method "test_day_of_month_dst_start_rule_for_#{rule}" do
|
167
|
-
result = @parser.parse("STD-1DST,#{rule},300")
|
168
|
-
expected_dst_start_rule = DayOfMonthTransitionRule.new(expected_month, expected_week, expected_day_of_week, expected_offset_from_midnight)
|
169
|
-
assert_equal(expected_dst_start_rule, result.dst_start_rule)
|
170
|
-
end
|
171
|
-
|
172
|
-
define_method "test_day_of_month_dst_end_rule_for_#{rule}" do
|
173
|
-
result = @parser.parse("STD-1DST,60,#{rule}")
|
174
|
-
expected_dst_end_rule = DayOfMonthTransitionRule.new(expected_month, expected_week, expected_day_of_week, expected_offset_from_midnight)
|
175
|
-
assert_equal(expected_dst_end_rule, result.dst_end_rule)
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
[
|
180
|
-
['M1.5.0', 1, 0],
|
181
|
-
['M12.5.6', 12, 6]
|
182
|
-
].each do |(last_day_of_month_rule, expected_month, expected_day_of_week)|
|
183
|
-
rule = append_time_to_rule(last_day_of_month_rule, time)
|
184
|
-
|
185
|
-
define_method "test_last_day_of_month_dst_start_rule_for_#{rule}" do
|
186
|
-
result = @parser.parse("STD-1DST,#{rule},300")
|
187
|
-
expected_dst_start_rule = LastDayOfMonthTransitionRule.new(expected_month, expected_day_of_week, expected_offset_from_midnight)
|
188
|
-
assert_equal(expected_dst_start_rule, result.dst_start_rule)
|
189
|
-
end
|
190
|
-
|
191
|
-
define_method "test_last_day_of_month_dst_end_rule_for_#{rule}" do
|
192
|
-
result = @parser.parse("STD-1DST,60,#{rule}")
|
193
|
-
expected_dst_end_rule = LastDayOfMonthTransitionRule.new(expected_month, expected_day_of_week, expected_offset_from_midnight)
|
194
|
-
assert_equal(expected_dst_end_rule, result.dst_end_rule)
|
195
|
-
end
|
196
|
-
end
|
197
|
-
end
|
198
|
-
|
199
|
-
['J0', 'J366'].each do |julian_day_rule|
|
200
|
-
define_invalid_dst_rule_tests('julian_day', julian_day_rule)
|
201
|
-
end
|
202
|
-
|
203
|
-
['-1', '366'].each do |absolute_day_rule|
|
204
|
-
define_invalid_dst_rule_tests('absolute_day', absolute_day_rule)
|
205
|
-
end
|
206
|
-
|
207
|
-
['M0,1,0', 'M13,1,0', 'M6,0,0', 'M6,6,0', 'M6,1,-1', 'M6,1,7'].each do |day_of_month_rule|
|
208
|
-
define_invalid_dst_rule_tests('day_of_month', day_of_month_rule)
|
209
|
-
end
|
210
|
-
|
211
|
-
['M0,5,0', 'M13,5,0', 'M6,5,-1', 'M6,5,7'].each do |last_day_of_month_rule|
|
212
|
-
define_invalid_dst_rule_tests('last_day_of_month', last_day_of_month_rule)
|
213
|
-
end
|
214
|
-
|
215
|
-
def test_invalid_dst_start_rule
|
216
|
-
assert_raises(InvalidPosixTimeZone) { @parser.parse('STD1DST,X60,300') }
|
217
|
-
end
|
218
|
-
|
219
|
-
def test_invalid_dst_end_rule
|
220
|
-
assert_raises(InvalidPosixTimeZone) { @parser.parse('STD1DST,60,X300') }
|
221
|
-
end
|
222
|
-
|
223
|
-
[
|
224
|
-
['STD5DST,0/0,J365/25', :DST, -5 * HOUR, HOUR],
|
225
|
-
['STD-5DST,0/0,J365/25', :DST, 5 * HOUR, HOUR],
|
226
|
-
['STD5DST3,0/0,J365/26', :DST, -5 * HOUR, 2 * HOUR],
|
227
|
-
['STD5DST6,0/0,J365/23', :DST, -5 * HOUR, -HOUR],
|
228
|
-
['STD5DST,J1/0,J365/25', :DST, -5 * HOUR, HOUR],
|
229
|
-
['Winter5Summer,0/0,J365/25', :Summer, -5 * HOUR, HOUR],
|
230
|
-
['<-05>5<-06>,0/0,J365/25', :'-06', -5 * HOUR, HOUR]
|
231
|
-
].each do |(tz_string, expected_abbrev, expected_base_offset, expected_std_offset)|
|
232
|
-
define_method "test_dst_only_returns_continuous_offset_for_#{tz_string}" do
|
233
|
-
result = @parser.parse(tz_string)
|
234
|
-
expected = TimezoneOffset.new(expected_base_offset, expected_std_offset, expected_abbrev)
|
235
|
-
assert_equal(expected, result)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
def test_parses_tainted_string_in_safe_mode_and_returns_untainted_abbreviations
|
240
|
-
safe_test(:unavailable => :skip) do
|
241
|
-
result = @parser.parse('STD1DST,60,300'.dup.taint)
|
242
|
-
|
243
|
-
assert_equal(:STD, result.std_offset.abbreviation)
|
244
|
-
assert_equal(:DST, result.dst_offset.abbreviation)
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
['STD1', 'STD1DST,60,300'].each do |tz_string|
|
249
|
-
tz_string += "-"
|
250
|
-
define_method "test_content_after_end_for_#{tz_string}" do
|
251
|
-
error = assert_raises(InvalidPosixTimeZone) { @parser.parse(tz_string) }
|
252
|
-
assert_equal("Expected the end of a POSIX-style time zone string but found '-'.", error.message)
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
['X', 0].each do |invalid_tz_string|
|
257
|
-
define_method "test_invalid_tz_string_#{invalid_tz_string}" do
|
258
|
-
assert_raises(InvalidPosixTimeZone) { @parser.parse(invalid_tz_string) }
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
@@ -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
|