tzinfo 1.2.10 → 2.0.5
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 +573 -391
- data/LICENSE +12 -12
- 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 +181 -0
- data/lib/tzinfo/data_sources/ruby_data_source.rb +145 -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 +596 -0
- data/lib/tzinfo/data_sources/zoneinfo_reader.rb +486 -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 +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/untaint_ext.rb +18 -0
- data/lib/tzinfo/version.rb +7 -0
- data/lib/tzinfo/with_offset.rb +61 -0
- data/lib/tzinfo.rb +82 -40
- data.tar.gz.sig +0 -0
- metadata +49 -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_core_support.rb +0 -169
- 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 -512
- data/lib/tzinfo/zoneinfo_timezone_info.rb +0 -520
- data/test/assets/payload.rb +0 -1
- 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 -173
- 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 -1223
- data/test/tc_zoneinfo_timezone_info.rb +0 -2153
- data/test/test_utils.rb +0 -208
- 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_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
|
@@ -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
|