tzinfo 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of tzinfo might be problematic. Click here for more details.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +0 -0
- data/.yardopts +6 -0
- data/CHANGES.md +786 -0
- data/LICENSE +19 -0
- data/README.md +151 -0
- data/Rakefile +107 -0
- data/lib/tzinfo.rb +40 -0
- data/lib/tzinfo/country.rb +196 -0
- data/lib/tzinfo/country_index_definition.rb +31 -0
- data/lib/tzinfo/country_info.rb +42 -0
- data/lib/tzinfo/country_timezone.rb +135 -0
- data/lib/tzinfo/data_source.rb +190 -0
- data/lib/tzinfo/data_timezone.rb +58 -0
- data/lib/tzinfo/data_timezone_info.rb +55 -0
- data/lib/tzinfo/info_timezone.rb +30 -0
- data/lib/tzinfo/linked_timezone.rb +63 -0
- data/lib/tzinfo/linked_timezone_info.rb +26 -0
- data/lib/tzinfo/offset_rationals.rb +77 -0
- data/lib/tzinfo/ruby_core_support.rb +146 -0
- data/lib/tzinfo/ruby_country_info.rb +74 -0
- data/lib/tzinfo/ruby_data_source.rb +136 -0
- data/lib/tzinfo/time_or_datetime.rb +340 -0
- data/lib/tzinfo/timezone.rb +669 -0
- data/lib/tzinfo/timezone_definition.rb +36 -0
- data/lib/tzinfo/timezone_index_definition.rb +54 -0
- data/lib/tzinfo/timezone_info.rb +30 -0
- data/lib/tzinfo/timezone_offset.rb +101 -0
- data/lib/tzinfo/timezone_period.rb +245 -0
- data/lib/tzinfo/timezone_proxy.rb +105 -0
- data/lib/tzinfo/timezone_transition.rb +130 -0
- data/lib/tzinfo/timezone_transition_definition.rb +104 -0
- data/lib/tzinfo/transition_data_timezone_info.rb +274 -0
- data/lib/tzinfo/zoneinfo_country_info.rb +37 -0
- data/lib/tzinfo/zoneinfo_data_source.rb +488 -0
- data/lib/tzinfo/zoneinfo_timezone_info.rb +296 -0
- data/test/tc_country.rb +234 -0
- data/test/tc_country_index_definition.rb +69 -0
- data/test/tc_country_info.rb +16 -0
- data/test/tc_country_timezone.rb +173 -0
- data/test/tc_data_source.rb +218 -0
- data/test/tc_data_timezone.rb +99 -0
- data/test/tc_data_timezone_info.rb +18 -0
- data/test/tc_info_timezone.rb +34 -0
- data/test/tc_linked_timezone.rb +155 -0
- data/test/tc_linked_timezone_info.rb +23 -0
- data/test/tc_offset_rationals.rb +23 -0
- data/test/tc_ruby_core_support.rb +168 -0
- data/test/tc_ruby_country_info.rb +110 -0
- data/test/tc_ruby_data_source.rb +143 -0
- data/test/tc_time_or_datetime.rb +654 -0
- data/test/tc_timezone.rb +1350 -0
- data/test/tc_timezone_definition.rb +113 -0
- data/test/tc_timezone_index_definition.rb +73 -0
- data/test/tc_timezone_info.rb +11 -0
- data/test/tc_timezone_london.rb +143 -0
- data/test/tc_timezone_melbourne.rb +142 -0
- data/test/tc_timezone_new_york.rb +142 -0
- data/test/tc_timezone_offset.rb +126 -0
- data/test/tc_timezone_period.rb +555 -0
- data/test/tc_timezone_proxy.rb +136 -0
- data/test/tc_timezone_transition.rb +366 -0
- data/test/tc_timezone_transition_definition.rb +295 -0
- data/test/tc_timezone_utc.rb +27 -0
- data/test/tc_transition_data_timezone_info.rb +423 -0
- data/test/tc_zoneinfo_country_info.rb +78 -0
- data/test/tc_zoneinfo_data_source.rb +1195 -0
- data/test/tc_zoneinfo_timezone_info.rb +1232 -0
- data/test/test_utils.rb +163 -0
- data/test/ts_all.rb +7 -0
- data/test/ts_all_ruby.rb +5 -0
- data/test/ts_all_zoneinfo.rb +7 -0
- data/test/tzinfo-data/tzinfo/data.rb +8 -0
- data/test/tzinfo-data/tzinfo/data/definitions/America/Argentina/Buenos_Aires.rb +89 -0
- data/test/tzinfo-data/tzinfo/data/definitions/America/New_York.rb +315 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Australia/Melbourne.rb +218 -0
- data/test/tzinfo-data/tzinfo/data/definitions/EST.rb +19 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__m__1.rb +21 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/GMT__p__1.rb +21 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Etc/UTC.rb +21 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Amsterdam.rb +261 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Andorra.rb +186 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/London.rb +321 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Paris.rb +265 -0
- data/test/tzinfo-data/tzinfo/data/definitions/Europe/Prague.rb +220 -0
- data/test/tzinfo-data/tzinfo/data/definitions/UTC.rb +16 -0
- data/test/tzinfo-data/tzinfo/data/indexes/countries.rb +927 -0
- data/test/tzinfo-data/tzinfo/data/indexes/timezones.rb +596 -0
- data/test/tzinfo-data/tzinfo/data/version.rb +14 -0
- 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 +275 -0
- data/test/zoneinfo/leapseconds +61 -0
- 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 +439 -0
- data/test/zoneinfo/zone1970.tab +369 -0
- data/tzinfo.gemspec +21 -0
- metadata +193 -0
- metadata.gz.sig +2 -0
@@ -0,0 +1,136 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
|
2
|
+
|
3
|
+
include TZInfo
|
4
|
+
|
5
|
+
class TCTimezoneProxy < Minitest::Test
|
6
|
+
def test_not_exist
|
7
|
+
proxy = TimezoneProxy.new('Nothing/Special')
|
8
|
+
t = Time.utc(2006,1,1,0,0,0)
|
9
|
+
assert_equal('Nothing/Special', proxy.identifier)
|
10
|
+
assert_equal('Nothing/Special', proxy.name)
|
11
|
+
assert_equal('Nothing - Special', proxy.friendly_identifier)
|
12
|
+
assert_equal('Nothing - Special', proxy.to_s)
|
13
|
+
|
14
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.canonical_identifier }
|
15
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.canonical_zone }
|
16
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.current_period }
|
17
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.current_period_and_time }
|
18
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.current_time_and_period }
|
19
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.local_to_utc(t) }
|
20
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.now }
|
21
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.offsets_up_to(t) }
|
22
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.period_for_local(t) }
|
23
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.period_for_utc(t) }
|
24
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.periods_for_local(t) }
|
25
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.strftime('%Z', t) }
|
26
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.transitions_up_to(t) }
|
27
|
+
assert_raises(InvalidTimezoneIdentifier) { proxy.utc_to_local(t) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_valid
|
31
|
+
proxy = TimezoneProxy.new('Europe/London')
|
32
|
+
real = Timezone.get('Europe/London')
|
33
|
+
|
34
|
+
t1 = Time.utc(2005,8,1,0,0,0)
|
35
|
+
t2 = Time.utc(2004,8,1,0,0,0)
|
36
|
+
|
37
|
+
assert_equal(real.canonical_identifier, proxy.canonical_identifier)
|
38
|
+
assert_same(real.canonical_zone, proxy.canonical_zone)
|
39
|
+
assert_nothing_raised { proxy.current_period }
|
40
|
+
assert_nothing_raised { proxy.current_period_and_time }
|
41
|
+
assert_nothing_raised { proxy.current_time_and_period }
|
42
|
+
assert_equal(real.friendly_identifier(true), proxy.friendly_identifier(true))
|
43
|
+
assert_equal(real.friendly_identifier(false), proxy.friendly_identifier(false))
|
44
|
+
assert_equal(real.friendly_identifier, proxy.friendly_identifier)
|
45
|
+
assert_equal(real.identifier, proxy.identifier)
|
46
|
+
assert_equal(real.local_to_utc(t1), proxy.local_to_utc(t1))
|
47
|
+
assert_equal(real.name, proxy.name)
|
48
|
+
assert_nothing_raised { proxy.now }
|
49
|
+
assert_equal(real.offsets_up_to(t1), proxy.offsets_up_to(t1))
|
50
|
+
assert_equal(real.offsets_up_to(t1, t2), proxy.offsets_up_to(t1, t2))
|
51
|
+
assert_equal(real.period_for_local(t1), proxy.period_for_local(t1))
|
52
|
+
assert_equal(real.period_for_utc(t1), proxy.period_for_utc(t1))
|
53
|
+
assert_equal(real.periods_for_local(t1), proxy.periods_for_local(t1))
|
54
|
+
assert_equal(real.strftime('%Z', t1), proxy.strftime('%Z', t1))
|
55
|
+
assert_equal(real.to_s, proxy.to_s)
|
56
|
+
assert_equal(real.transitions_up_to(t1), proxy.transitions_up_to(t1))
|
57
|
+
assert_equal(real.transitions_up_to(t1, t2), proxy.transitions_up_to(t1, t2))
|
58
|
+
assert_equal(real.utc_to_local(t1), proxy.utc_to_local(t1))
|
59
|
+
|
60
|
+
|
61
|
+
assert(real == proxy)
|
62
|
+
assert(proxy == real)
|
63
|
+
assert_equal(0, real <=> proxy)
|
64
|
+
assert_equal(0, proxy <=> real)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_canonical_linked
|
68
|
+
# Test that the implementation of canonical_zone and canonical_identifier
|
69
|
+
# are actually calling the real timezone and not just returning it and
|
70
|
+
# its identifier.
|
71
|
+
|
72
|
+
real = Timezone.get('UTC')
|
73
|
+
proxy = TimezoneProxy.new('UTC')
|
74
|
+
|
75
|
+
# ZoneinfoDataSource doesn't return LinkedTimezoneInfo instances for any
|
76
|
+
# timezone.
|
77
|
+
if real.kind_of?(LinkedTimezone)
|
78
|
+
assert_equal('Etc/UTC', proxy.canonical_identifier)
|
79
|
+
assert_same(Timezone.get('Etc/UTC'), proxy.canonical_zone)
|
80
|
+
else
|
81
|
+
if DataSource.get.kind_of?(RubyDataSource)
|
82
|
+
# Not got a LinkedTimezone despite using a DataSource that supports it.
|
83
|
+
# Raise an exception as this shouldn't happen.
|
84
|
+
raise 'Non-LinkedTimezone instance returned for UTC using RubyDataSource'
|
85
|
+
end
|
86
|
+
|
87
|
+
assert_equal('UTC', proxy.canonical_identifier)
|
88
|
+
assert_same(Timezone.get('UTC'), proxy.canonical_zone)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_after_freeze
|
93
|
+
proxy = TimezoneProxy.new('Europe/London')
|
94
|
+
real = Timezone.get('Europe/London')
|
95
|
+
t = Time.utc(2017, 6, 1)
|
96
|
+
proxy.freeze
|
97
|
+
assert_equal('Europe/London', proxy.identifier)
|
98
|
+
assert_equal(real.utc_to_local(t), proxy.utc_to_local(t))
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_equals
|
102
|
+
assert_equal(true, TimezoneProxy.new('Europe/London') == TimezoneProxy.new('Europe/London'))
|
103
|
+
assert_equal(false, TimezoneProxy.new('Europe/London') == TimezoneProxy.new('Europe/Paris'))
|
104
|
+
assert(!(TimezoneProxy.new('Europe/London') == Object.new))
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_compare
|
108
|
+
assert_equal(0, TimezoneProxy.new('Europe/London') <=> TimezoneProxy.new('Europe/London'))
|
109
|
+
assert_equal(0, Timezone.get('Europe/London') <=> TimezoneProxy.new('Europe/London'))
|
110
|
+
assert_equal(0, TimezoneProxy.new('Europe/London') <=> Timezone.get('Europe/London'))
|
111
|
+
assert_equal(-1, TimezoneProxy.new('Europe/London') <=> TimezoneProxy.new('Europe/Paris'))
|
112
|
+
assert_equal(-1, Timezone.get('Europe/London') <=> TimezoneProxy.new('Europe/Paris'))
|
113
|
+
assert_equal(-1, TimezoneProxy.new('Europe/London') <=> Timezone.get('Europe/Paris'))
|
114
|
+
assert_equal(1, TimezoneProxy.new('Europe/Paris') <=> TimezoneProxy.new('Europe/London'))
|
115
|
+
assert_equal(1, Timezone.get('Europe/Paris') <=> TimezoneProxy.new('Europe/London'))
|
116
|
+
assert_equal(1, TimezoneProxy.new('Europe/Paris') <=> Timezone.get('Europe/London'))
|
117
|
+
assert_equal(-1, TimezoneProxy.new('America/New_York') <=> TimezoneProxy.new('Europe/Paris'))
|
118
|
+
assert_equal(-1, Timezone.get('America/New_York') <=> TimezoneProxy.new('Europe/Paris'))
|
119
|
+
assert_equal(-1, TimezoneProxy.new('America/New_York') <=> Timezone.get('Europe/Paris'))
|
120
|
+
assert_equal(1, TimezoneProxy.new('Europe/Paris') <=> TimezoneProxy.new('America/New_York'))
|
121
|
+
assert_equal(1, Timezone.get('Europe/Paris') <=> TimezoneProxy.new('America/New_York'))
|
122
|
+
assert_equal(1, TimezoneProxy.new('Europe/Paris') <=> Timezone.get('America/New_York'))
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_kind
|
126
|
+
assert_kind_of(Timezone, TimezoneProxy.new('America/New_York'))
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_marshal
|
130
|
+
tp = TimezoneProxy.new('Europe/London')
|
131
|
+
tp2 = Marshal.load(Marshal.dump(tp))
|
132
|
+
|
133
|
+
assert_kind_of(TimezoneProxy, tp2)
|
134
|
+
assert_equal('Europe/London', tp2.identifier)
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,366 @@
|
|
1
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), 'test_utils')
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
include TZInfo
|
5
|
+
|
6
|
+
class TCTimezoneTransition < Minitest::Test
|
7
|
+
|
8
|
+
class TestTimezoneTransition < TimezoneTransition
|
9
|
+
def initialize(offset, previous_offset, at)
|
10
|
+
super(offset, previous_offset)
|
11
|
+
@at = TimeOrDateTime.wrap(at)
|
12
|
+
end
|
13
|
+
|
14
|
+
def at
|
15
|
+
@at
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_offset
|
20
|
+
t = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
21
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
22
|
+
|
23
|
+
assert_equal(TimezoneOffset.new(3600, 3600, :TDT), t.offset)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_previous_offset
|
27
|
+
t = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
28
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
29
|
+
|
30
|
+
assert_equal(TimezoneOffset.new(3600, 0, :TST), t.previous_offset)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_datetime
|
34
|
+
t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
35
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
36
|
+
t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
37
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
38
|
+
t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
39
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
|
40
|
+
|
41
|
+
assert_equal(DateTime.new(2006, 5, 30, 0, 31, 20), t1.datetime)
|
42
|
+
assert_equal(DateTime.new(2006, 5, 30, 0, 31, 20), t2.datetime)
|
43
|
+
assert_equal(DateTime.new(2006, 5, 30, 0, 31, 20), t3.datetime)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_time
|
47
|
+
t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
48
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
49
|
+
t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
50
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
51
|
+
t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
52
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
|
53
|
+
|
54
|
+
assert_equal(Time.utc(2006, 5, 30, 0, 31, 20), t1.time)
|
55
|
+
assert_equal(Time.utc(2006, 5, 30, 0, 31, 20), t2.time)
|
56
|
+
assert_equal(Time.utc(2006, 5, 30, 0, 31, 20), t3.time)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_local_end_at
|
60
|
+
t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
61
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
62
|
+
t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
63
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
64
|
+
t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
65
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
|
66
|
+
|
67
|
+
assert(TimeOrDateTime.new(1148952680).eql?(t1.local_end_at))
|
68
|
+
assert(TimeOrDateTime.new(DateTime.new(2006, 5, 30, 1, 31, 20)).eql?(t2.local_end_at))
|
69
|
+
assert(TimeOrDateTime.new(Time.utc(2006, 5, 30, 1, 31, 20)).eql?(t3.local_end_at))
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_local_end_at_after_freeze
|
73
|
+
t = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
74
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
75
|
+
t.freeze
|
76
|
+
assert(TimeOrDateTime.new(1148952680).eql?(t.local_end_at))
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_local_end
|
80
|
+
t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
81
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
82
|
+
t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
83
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
84
|
+
t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
85
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
|
86
|
+
|
87
|
+
assert_equal(DateTime.new(2006, 5, 30, 1, 31, 20), t1.local_end)
|
88
|
+
assert_equal(DateTime.new(2006, 5, 30, 1, 31, 20), t2.local_end)
|
89
|
+
assert_equal(DateTime.new(2006, 5, 30, 1, 31, 20), t3.local_end)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_local_end_time
|
93
|
+
t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
94
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
95
|
+
t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
96
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
97
|
+
t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
98
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
|
99
|
+
|
100
|
+
assert_equal(Time.utc(2006, 5, 30, 1, 31, 20), t1.local_end_time)
|
101
|
+
assert_equal(Time.utc(2006, 5, 30, 1, 31, 20), t2.local_end_time)
|
102
|
+
assert_equal(Time.utc(2006, 5, 30, 1, 31, 20), t3.local_end_time)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_local_start_at
|
106
|
+
t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
107
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
108
|
+
t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
109
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
110
|
+
t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
111
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
|
112
|
+
|
113
|
+
assert(TimeOrDateTime.new(1148956280).eql?(t1.local_start_at))
|
114
|
+
assert(TimeOrDateTime.new(DateTime.new(2006, 5, 30, 2, 31, 20)).eql?(t2.local_start_at))
|
115
|
+
assert(TimeOrDateTime.new(Time.utc(2006, 5, 30, 2, 31, 20)).eql?(t3.local_start_at))
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_local_start_at_after_freeze
|
119
|
+
t = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
120
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
121
|
+
t.freeze
|
122
|
+
assert(TimeOrDateTime.new(1148956280).eql?(t.local_start_at))
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_local_start
|
126
|
+
t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
127
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
128
|
+
t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
129
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
130
|
+
t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
131
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
|
132
|
+
|
133
|
+
assert_equal(DateTime.new(2006, 5, 30, 2, 31, 20), t1.local_start)
|
134
|
+
assert_equal(DateTime.new(2006, 5, 30, 2, 31, 20), t2.local_start)
|
135
|
+
assert_equal(DateTime.new(2006, 5, 30, 2, 31, 20), t3.local_start)
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_local_start_time
|
139
|
+
t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
140
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
141
|
+
t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
142
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
143
|
+
t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
144
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
|
145
|
+
|
146
|
+
assert_equal(Time.utc(2006, 5, 30, 2, 31, 20), t1.local_start_time)
|
147
|
+
assert_equal(Time.utc(2006, 5, 30, 2, 31, 20), t2.local_start_time)
|
148
|
+
assert_equal(Time.utc(2006, 5, 30, 2, 31, 20), t3.local_start_time)
|
149
|
+
end
|
150
|
+
|
151
|
+
if RubyCoreSupport.time_supports_negative
|
152
|
+
def test_local_end_at_before_negative_32bit
|
153
|
+
t = TestTimezoneTransition.new(TimezoneOffset.new(-7200, 3600, :TDT),
|
154
|
+
TimezoneOffset.new(-7200, 0, :TST), -2147482800)
|
155
|
+
|
156
|
+
if RubyCoreSupport.time_supports_64bit
|
157
|
+
assert(TimeOrDateTime.new(-2147490000).eql?(t.local_end_at))
|
158
|
+
else
|
159
|
+
assert(TimeOrDateTime.new(DateTime.new(1901, 12, 13, 19, 0, 0)).eql?(t.local_end_at))
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_local_start_at_before_negative_32bit
|
164
|
+
t = TestTimezoneTransition.new(TimezoneOffset.new(-7200, 3600, :TDT),
|
165
|
+
TimezoneOffset.new(-7200, 0, :TST), -2147482800)
|
166
|
+
|
167
|
+
if RubyCoreSupport.time_supports_64bit
|
168
|
+
assert(TimeOrDateTime.new(-2147486400).eql?(t.local_start_at))
|
169
|
+
else
|
170
|
+
assert(TimeOrDateTime.new(DateTime.new(1901, 12, 13, 20, 0, 0)).eql?(t.local_start_at))
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_local_end_at_before_epoch
|
176
|
+
t = TestTimezoneTransition.new(TimezoneOffset.new(-7200, 3600, :TDT),
|
177
|
+
TimezoneOffset.new(-7200, 0, :TST), 1800)
|
178
|
+
|
179
|
+
if RubyCoreSupport.time_supports_negative
|
180
|
+
assert(TimeOrDateTime.new(-5400).eql?(t.local_end_at))
|
181
|
+
else
|
182
|
+
assert(TimeOrDateTime.new(DateTime.new(1969, 12, 31, 22, 30, 0)).eql?(t.local_end_at))
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_local_start_at_before_epoch
|
187
|
+
t = TestTimezoneTransition.new(TimezoneOffset.new(-7200, 3600, :TDT),
|
188
|
+
TimezoneOffset.new(-7200, 0, :TST), 1800)
|
189
|
+
|
190
|
+
if RubyCoreSupport.time_supports_negative
|
191
|
+
assert(TimeOrDateTime.new(-1800).eql?(t.local_start_at))
|
192
|
+
else
|
193
|
+
assert(TimeOrDateTime.new(DateTime.new(1969, 12, 31, 23, 30, 0)).eql?(t.local_start_at))
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_local_end_at_after_32bit
|
198
|
+
t = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
199
|
+
TimezoneOffset.new(3600, 0, :TST), 2147482800)
|
200
|
+
|
201
|
+
if RubyCoreSupport.time_supports_64bit
|
202
|
+
assert(TimeOrDateTime.new(2147486400).eql?(t.local_end_at))
|
203
|
+
else
|
204
|
+
assert(TimeOrDateTime.new(DateTime.new(2038, 1, 19, 4, 0, 0)).eql?(t.local_end_at))
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def test_local_start_at_after_32bit
|
209
|
+
t = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
210
|
+
TimezoneOffset.new(3600, 0, :TST), 2147482800)
|
211
|
+
|
212
|
+
if RubyCoreSupport.time_supports_64bit
|
213
|
+
assert(TimeOrDateTime.new(2147490000).eql?(t.local_start_at))
|
214
|
+
else
|
215
|
+
assert(TimeOrDateTime.new(DateTime.new(2038, 1, 19, 5, 0, 0)).eql?(t.local_start_at))
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_equality_timestamp
|
220
|
+
t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
221
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
222
|
+
t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
223
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
224
|
+
t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
225
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
226
|
+
t4 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
227
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
|
228
|
+
t5 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
229
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949081)
|
230
|
+
t6 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
231
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 1, 31, 21))
|
232
|
+
t7 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
233
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 1, 31, 21))
|
234
|
+
t8 = TestTimezoneTransition.new(TimezoneOffset.new(3601, 3600, :TDT),
|
235
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
236
|
+
t9 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
237
|
+
TimezoneOffset.new(3601, 0, :TST), 1148949080)
|
238
|
+
|
239
|
+
assert_equal(true, t1 == t1)
|
240
|
+
assert_equal(true, t1 == t2)
|
241
|
+
assert_equal(true, t1 == t3)
|
242
|
+
assert_equal(true, t1 == t4)
|
243
|
+
assert_equal(false, t1 == t5)
|
244
|
+
assert_equal(false, t1 == t6)
|
245
|
+
assert_equal(false, t1 == t7)
|
246
|
+
assert_equal(false, t1 == t8)
|
247
|
+
assert_equal(false, t1 == t9)
|
248
|
+
assert_equal(false, t1 == Object.new)
|
249
|
+
|
250
|
+
assert_equal(true, t1.eql?(t1))
|
251
|
+
assert_equal(true, t1.eql?(t2))
|
252
|
+
assert_equal(false, t1.eql?(t3))
|
253
|
+
assert_equal(false, t1.eql?(t4))
|
254
|
+
assert_equal(false, t1.eql?(t5))
|
255
|
+
assert_equal(false, t1.eql?(t6))
|
256
|
+
assert_equal(false, t1.eql?(t7))
|
257
|
+
assert_equal(false, t1.eql?(t8))
|
258
|
+
assert_equal(false, t1.eql?(t9))
|
259
|
+
assert_equal(false, t1.eql?(Object.new))
|
260
|
+
end
|
261
|
+
|
262
|
+
def test_equality_datetime
|
263
|
+
t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
264
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
265
|
+
t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
266
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
267
|
+
t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
268
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
269
|
+
t4 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
270
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
|
271
|
+
t5 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
272
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 1, 31, 21))
|
273
|
+
t6 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
274
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949081)
|
275
|
+
t7 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
276
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 1, 31, 21))
|
277
|
+
t8 = TestTimezoneTransition.new(TimezoneOffset.new(3601, 3600, :TDT),
|
278
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
279
|
+
t9 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
280
|
+
TimezoneOffset.new(3601, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
281
|
+
|
282
|
+
assert_equal(true, t1 == t1)
|
283
|
+
assert_equal(true, t1 == t2)
|
284
|
+
assert_equal(true, t1 == t3)
|
285
|
+
assert_equal(true, t1 == t4)
|
286
|
+
assert_equal(false, t1 == t5)
|
287
|
+
assert_equal(false, t1 == t6)
|
288
|
+
assert_equal(false, t1 == t7)
|
289
|
+
assert_equal(false, t1 == t8)
|
290
|
+
assert_equal(false, t1 == t9)
|
291
|
+
assert_equal(false, t1 == Object.new)
|
292
|
+
|
293
|
+
assert_equal(true, t1.eql?(t1))
|
294
|
+
assert_equal(true, t1.eql?(t2))
|
295
|
+
assert_equal(false, t1.eql?(t3))
|
296
|
+
assert_equal(false, t1.eql?(t4))
|
297
|
+
assert_equal(false, t1.eql?(t5))
|
298
|
+
assert_equal(false, t1.eql?(t6))
|
299
|
+
assert_equal(false, t1.eql?(t7))
|
300
|
+
assert_equal(false, t1.eql?(t8))
|
301
|
+
assert_equal(false, t1.eql?(t9))
|
302
|
+
assert_equal(false, t1.eql?(Object.new))
|
303
|
+
end
|
304
|
+
|
305
|
+
def test_equality_time
|
306
|
+
t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
307
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
|
308
|
+
t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
309
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 20))
|
310
|
+
t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
311
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 0, 31, 20))
|
312
|
+
t4 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
313
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
314
|
+
t5 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
315
|
+
TimezoneOffset.new(3600, 0, :TST), Time.utc(2006, 5, 30, 0, 31, 21))
|
316
|
+
t6 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
317
|
+
TimezoneOffset.new(3600, 0, :TST), DateTime.new(2006, 5, 30, 1, 31, 21))
|
318
|
+
t7 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
319
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949081)
|
320
|
+
t8 = TestTimezoneTransition.new(TimezoneOffset.new(3601, 3600, :TDT),
|
321
|
+
TimezoneOffset.new(3600, 0, :TST), 1148949080)
|
322
|
+
t9 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDT),
|
323
|
+
TimezoneOffset.new(3601, 0, :TST), 1148949080)
|
324
|
+
|
325
|
+
assert_equal(true, t1 == t1)
|
326
|
+
assert_equal(true, t1 == t2)
|
327
|
+
assert_equal(true, t1 == t3)
|
328
|
+
assert_equal(true, t1 == t4)
|
329
|
+
assert_equal(false, t1 == t5)
|
330
|
+
assert_equal(false, t1 == t6)
|
331
|
+
assert_equal(false, t1 == t7)
|
332
|
+
assert_equal(false, t1 == t8)
|
333
|
+
assert_equal(false, t1 == t9)
|
334
|
+
assert_equal(false, t1 == Object.new)
|
335
|
+
|
336
|
+
assert_equal(true, t1.eql?(t1))
|
337
|
+
assert_equal(true, t1.eql?(t2))
|
338
|
+
assert_equal(false, t1.eql?(t3))
|
339
|
+
assert_equal(false, t1.eql?(t4))
|
340
|
+
assert_equal(false, t1.eql?(t5))
|
341
|
+
assert_equal(false, t1.eql?(t6))
|
342
|
+
assert_equal(false, t1.eql?(t7))
|
343
|
+
assert_equal(false, t1.eql?(t8))
|
344
|
+
assert_equal(false, t1.eql?(t9))
|
345
|
+
assert_equal(false, t1.eql?(Object.new))
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_hash
|
349
|
+
t1 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDTA),
|
350
|
+
TimezoneOffset.new(3600, 0, :TSTA), 1148949080)
|
351
|
+
t2 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDTB),
|
352
|
+
TimezoneOffset.new(3600, 0, :TSTB), DateTime.new(2006, 5, 30, 1, 31, 20))
|
353
|
+
t3 = TestTimezoneTransition.new(TimezoneOffset.new(3600, 3600, :TDTC),
|
354
|
+
TimezoneOffset.new(3600, 0, :TSTC), Time.utc(2006, 5, 30, 1, 31, 20))
|
355
|
+
|
356
|
+
assert_equal(TimezoneOffset.new(3600, 3600, :TDTA).hash ^
|
357
|
+
TimezoneOffset.new(3600, 0, :TSTA).hash ^ TimeOrDateTime.new(1148949080).hash,
|
358
|
+
t1.hash)
|
359
|
+
assert_equal(TimezoneOffset.new(3600, 3600, :TDTB).hash ^
|
360
|
+
TimezoneOffset.new(3600, 0, :TSTB).hash ^ TimeOrDateTime.new(DateTime.new(2006, 5, 30, 1, 31, 20)).hash,
|
361
|
+
t2.hash)
|
362
|
+
assert_equal(TimezoneOffset.new(3600, 3600, :TDTC).hash ^
|
363
|
+
TimezoneOffset.new(3600, 0, :TSTC).hash ^ TimeOrDateTime.new(Time.utc(2006, 5, 30, 1, 31, 20)).hash,
|
364
|
+
t3.hash)
|
365
|
+
end
|
366
|
+
end
|