timezone 0.99.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.markdown +6 -0
- data/README.markdown +1 -11
- data/Rakefile +3 -1
- data/data/America/Caracas +2 -1
- data/data/Asia/Almaty +51 -48
- data/data/Asia/Anadyr +3 -3
- data/data/Asia/Aqtau +50 -50
- data/data/Asia/Aqtobe +51 -49
- data/data/Asia/Baku +2 -2
- data/data/Asia/Barnaul +3 -3
- data/data/Asia/Chita +3 -3
- data/data/Asia/Irkutsk +3 -3
- data/data/Asia/Kamchatka +3 -3
- data/data/Asia/Khandyga +3 -3
- data/data/Asia/Krasnoyarsk +3 -3
- data/data/Asia/Magadan +5 -4
- data/data/Asia/Novokuznetsk +3 -3
- data/data/Asia/Novosibirsk +3 -3
- data/data/Asia/Omsk +3 -3
- data/data/Asia/Oral +51 -50
- data/data/Asia/Qyzylorda +51 -50
- data/data/Asia/Sakhalin +3 -3
- data/data/Asia/Srednekolymsk +3 -3
- data/data/Asia/Tomsk +68 -0
- data/data/Asia/Ust-Nera +3 -3
- data/data/Asia/Vladivostok +3 -3
- data/data/Asia/Yakutsk +3 -3
- data/data/Asia/Yekaterinburg +3 -3
- data/data/Asia/Yerevan +3 -3
- data/data/Europe/Astrakhan +2 -2
- data/data/Europe/Kaliningrad +3 -3
- data/data/Europe/Kirov +64 -0
- data/data/Europe/Minsk +2 -2
- data/data/Europe/Moscow +3 -3
- data/data/Europe/Samara +3 -3
- data/data/Europe/Ulyanovsk +3 -3
- data/data/Europe/Volgograd +2 -2
- data/data/W-SU +3 -3
- data/lib/timezone/error.rb +0 -4
- data/lib/timezone/lookup/basic.rb +1 -7
- data/lib/timezone/lookup/geonames.rb +7 -6
- data/lib/timezone/lookup/google.rb +2 -1
- data/lib/timezone/net_http_client.rb +1 -10
- data/lib/timezone/version.rb +1 -1
- data/lib/timezone/zone.rb +1 -122
- data/test/http_test_client.rb +1 -2
- data/test/mocks/{api_limit_reached.txt → api_limit_reached.json} +0 -0
- data/test/mocks/invalid_latlong.json +1 -0
- data/test/mocks/invalid_parameter.json +1 -0
- data/test/{basic_lookup_test.rb → timezone/lookup/test_basic.rb} +3 -1
- data/test/timezone/lookup/test_geonames.rb +33 -4
- data/test/timezone/test_zone.rb +211 -3
- data/timezone.gemspec +14 -13
- metadata +22 -26
- data/lib/timezone/active_support.rb +0 -156
- data/lib/timezone/configure.rb +0 -258
- data/test/geonames_lookup_test.rb +0 -56
- data/test/google_lookup_test.rb +0 -81
- data/test/test_lookup_test.rb +0 -41
- data/test/timezone_test.rb +0 -297
data/test/google_lookup_test.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'timezone/configure'
|
2
|
-
require 'timezone/lookup/google'
|
3
|
-
require 'minitest/autorun'
|
4
|
-
require 'timecop'
|
5
|
-
require_relative 'http_test_client'
|
6
|
-
|
7
|
-
class GoogleLookupTest < ::Minitest::Unit::TestCase
|
8
|
-
def setup
|
9
|
-
config { |c| c.google_api_key = 'MTIzYWJj' }
|
10
|
-
end
|
11
|
-
|
12
|
-
def coordinates
|
13
|
-
[-34.92771808058, 138.477041423321]
|
14
|
-
end
|
15
|
-
|
16
|
-
def lookup
|
17
|
-
::Timezone::Configure.lookup
|
18
|
-
end
|
19
|
-
|
20
|
-
def config
|
21
|
-
Timezone::Configure.instance_variable_set(:@lookup, nil)
|
22
|
-
Timezone::Configure.instance_variable_set(:@geonames_lookup, nil)
|
23
|
-
Timezone::Configure.instance_variable_set(:@google_lookup, nil)
|
24
|
-
|
25
|
-
Timezone::Configure.begin do |c|
|
26
|
-
c.http_client = HTTPTestClient
|
27
|
-
yield(c)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_google_using_lat_lon_coordinates
|
32
|
-
lookup.client.body =
|
33
|
-
File.open(mock_path + '/google_lat_lon_coords.txt').read
|
34
|
-
|
35
|
-
assert_equal 'Australia/Adelaide', lookup.lookup(*coordinates)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_google_request_denied_read_lat_lon_coordinates
|
39
|
-
lookup.client.body = nil
|
40
|
-
assert_raises Timezone::Error::Google do
|
41
|
-
lookup.lookup(*coordinates)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_url_non_enterprise
|
46
|
-
Timecop.freeze(Time.at(1_433_347_661)) do
|
47
|
-
result = lookup.send(:url, '123', '123')
|
48
|
-
params = {
|
49
|
-
'location' => '123%2C123',
|
50
|
-
'timestamp' => '1433347661',
|
51
|
-
'key' => 'MTIzYWJj'
|
52
|
-
}.map { |k, v| "#{k}=#{v}" }
|
53
|
-
|
54
|
-
assert_equal "/maps/api/timezone/json?#{params.join('&')}", result
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_url_enterprise
|
59
|
-
config { |c| c.google_client_id = '123&asdf' }
|
60
|
-
|
61
|
-
Timecop.freeze(Time.at(1_433_347_661)) do
|
62
|
-
result = lookup.send(:url, '123', '123')
|
63
|
-
params = {
|
64
|
-
'location' => '123%2C123',
|
65
|
-
'timestamp' => '1433347661',
|
66
|
-
'client' => '123%26asdf',
|
67
|
-
'signature' => 'B1TNSSvIw9Wvf_ZjjW5uRzGm4F4='
|
68
|
-
}.map { |k, v| "#{k}=#{v}" }
|
69
|
-
|
70
|
-
assert_equal "/maps/api/timezone/json?#{params.join('&')}", result
|
71
|
-
end
|
72
|
-
ensure
|
73
|
-
config { |c| c.google_client_id = nil }
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
def mock_path
|
79
|
-
File.expand_path(File.join(File.dirname(__FILE__), 'mocks'))
|
80
|
-
end
|
81
|
-
end
|
data/test/test_lookup_test.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'timezone/configure'
|
2
|
-
require 'timezone/lookup/test'
|
3
|
-
require 'timezone/zone'
|
4
|
-
require 'minitest/autorun'
|
5
|
-
|
6
|
-
class TestLookupTest < ::Minitest::Unit::TestCase
|
7
|
-
def setup
|
8
|
-
Timezone::Configure.begin do |c|
|
9
|
-
c.lookup = ::Timezone::Lookup::Test
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_simple_stub
|
14
|
-
::Timezone::Configure.lookup.stub(-10, 10, 'America/Los_Angeles')
|
15
|
-
|
16
|
-
assert_equal(
|
17
|
-
'America/Los_Angeles',
|
18
|
-
::Timezone::Zone.new(lat: -10, lon: 10).zone)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_missing_stub
|
22
|
-
assert_raises(::Timezone::Error::Test) do
|
23
|
-
::Timezone::Zone.new(lat: 100, lon: 100)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_clear_lookup
|
28
|
-
::Timezone::Configure.begin do |c|
|
29
|
-
c.username = 'foo'
|
30
|
-
c.lookup = nil
|
31
|
-
end
|
32
|
-
|
33
|
-
assert ::Timezone::Lookup::Geonames, ::Timezone::Configure.lookup.class
|
34
|
-
end
|
35
|
-
|
36
|
-
def teardown
|
37
|
-
Timezone::Configure.instance_variable_set(:@lookup, nil)
|
38
|
-
Timezone::Configure.instance_variable_set(:@google_lookup, nil)
|
39
|
-
Timezone::Configure.instance_variable_set(:@geonames_lookup, nil)
|
40
|
-
end
|
41
|
-
end
|
data/test/timezone_test.rb
DELETED
@@ -1,297 +0,0 @@
|
|
1
|
-
require 'timezone'
|
2
|
-
require 'timezone/zone'
|
3
|
-
require 'minitest/autorun'
|
4
|
-
require 'timecop'
|
5
|
-
|
6
|
-
class TimezoneTest < ::Minitest::Unit::TestCase
|
7
|
-
def test_valid_timezone
|
8
|
-
refute_nil(Timezone::Zone.new(zone: 'Australia/Sydney'))
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_nil_timezone
|
12
|
-
assert_raises Timezone::Error::NilZone do
|
13
|
-
Timezone::Zone.new zone: nil
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_invalid_timezone
|
18
|
-
assert_raises Timezone::Error::InvalidZone do
|
19
|
-
Timezone::Zone.new zone: 'Foo/Bar'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_timezone_list
|
24
|
-
list = Timezone::Zone.list 'Australia/Sydney', 'America/Chicago'
|
25
|
-
assert list.is_a?(Array)
|
26
|
-
assert list.count == 2
|
27
|
-
assert list.first.is_a?(Hash)
|
28
|
-
assert(list.any? { |l| l[:zone] == 'Australia/Sydney' })
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_timezone_list_current_time
|
32
|
-
Timecop.freeze(Time.new(2012, 2, 2, 0, 0, 0)) do
|
33
|
-
assert !Timezone::Zone.list('EST5EDT').first[:dst]
|
34
|
-
end
|
35
|
-
Timecop.freeze(Time.new(2013, 6, 6, 0, 0, 0)) do
|
36
|
-
assert Timezone::Zone.list('EST5EDT').first[:dst]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_timezone_custom_list_order
|
41
|
-
Timezone::Configure.order_list_by = :title
|
42
|
-
Timezone::Configure.replace 'America/Chicago', with: 'Chicago'
|
43
|
-
list = Timezone::Zone.list 'Australia/Sydney', 'America/Chicago'
|
44
|
-
assert list.first[:title] == 'Australia/Sydney'
|
45
|
-
assert list.last[:title] == 'Chicago'
|
46
|
-
assert list.last[:zone] == 'America/Chicago'
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_timezone_default_list
|
50
|
-
Timezone::Configure.default_for_list = 'America/Chicago', 'Australia/Sydney'
|
51
|
-
list = Timezone::Zone.list
|
52
|
-
assert list.count == 2
|
53
|
-
assert(list.any? { |l| l.value?('Australia/Sydney') })
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_timezone_names
|
57
|
-
zones = Timezone::Zone.names
|
58
|
-
assert zones.is_a?(Array)
|
59
|
-
assert zones.count > 0
|
60
|
-
assert zones.include? 'Australia/Sydney'
|
61
|
-
end
|
62
|
-
|
63
|
-
def time_timezone_equivalence
|
64
|
-
gmt = Timezone::Zone.new zone: 'GMT'
|
65
|
-
australia = Timezone::Zone.new zone: 'Australia/Sydney'
|
66
|
-
|
67
|
-
assert_equal(gmt, Timezone::Zone.new(zone: 'GMT'))
|
68
|
-
assert gmt <= australia
|
69
|
-
assert gmt < australia
|
70
|
-
end
|
71
|
-
|
72
|
-
def utc_offset(zone, year, month, day)
|
73
|
-
Timezone::Zone.new(zone: zone).utc_offset(Time.new(year, month, day))
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_getting_utc_offset
|
77
|
-
assert_equal(36_000, utc_offset('Australia/Sydney', 2011, 06, 05))
|
78
|
-
assert_equal(-25_200, utc_offset('America/Los_Angeles', 2011, 06, 05))
|
79
|
-
assert_equal(20_700, utc_offset('Asia/Kathmandu', 2011, 06, 05))
|
80
|
-
assert_equal(-18_000, utc_offset('America/New_York', 2011, 01, 11))
|
81
|
-
assert_equal(-14_400, utc_offset('America/New_York', 2011, 06, 11))
|
82
|
-
end
|
83
|
-
|
84
|
-
def dst?(zone, year, month, day)
|
85
|
-
Timezone::Zone.new(zone: zone).dst?(Time.new(year, month, day))
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_getting_dst
|
89
|
-
refute dst?('Australia/Sydney', 2011, 06, 05)
|
90
|
-
assert dst?('America/Los_Angeles', 2011, 06, 05)
|
91
|
-
refute dst?('Asia/Kathmandu', 2011, 06, 05)
|
92
|
-
|
93
|
-
refute dst?('America/New_York', 2011, 01, 11)
|
94
|
-
assert dst?('America/New_York', 2011, 06, 11)
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_loading_gmt_timezone
|
98
|
-
timezone = Timezone::Zone.new zone: 'GMT'
|
99
|
-
assert_equal Time.now.utc.to_i, timezone.time(Time.now).to_i
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_loading_historical_time
|
103
|
-
timezone = Timezone::Zone.new zone: 'America/Los_Angeles'
|
104
|
-
local = Time.strptime('2011-02-11T13:20:00Z', '%Y-%m-%dT%H:%M:%SZ')
|
105
|
-
utc = Time.strptime('2011-02-11T21:20:00Z', '%Y-%m-%dT%H:%M:%SZ')
|
106
|
-
assert_equal local.to_i, timezone.time(utc).to_i
|
107
|
-
end
|
108
|
-
|
109
|
-
# http://www.timeanddate.com/worldclock/clockchange.html?n=137&year=2011
|
110
|
-
def test_historical_time_change_in_la_forward
|
111
|
-
timezone = Timezone::Zone.new zone: 'America/Los_Angeles'
|
112
|
-
local = Time.strptime('2011-03-13T01:59:59 UTC', '%Y-%m-%dT%H:%M:%S %Z')
|
113
|
-
utc = Time.strptime('2011-03-13T09:59:59 UTC', '%Y-%m-%dT%H:%M:%S %Z')
|
114
|
-
assert_equal local.to_i, timezone.time(utc).to_i
|
115
|
-
|
116
|
-
timezone = Timezone::Zone.new zone: 'America/Los_Angeles'
|
117
|
-
local = Time.strptime('2011-03-13T03:00:00 UTC', '%Y-%m-%dT%H:%M:%S %Z')
|
118
|
-
utc = Time.strptime('2011-03-13T10:00:00 UTC', '%Y-%m-%dT%H:%M:%S %Z')
|
119
|
-
assert_equal local.to_i, timezone.time(utc).to_i
|
120
|
-
end
|
121
|
-
|
122
|
-
# http://www.timeanddate.com/worldclock/clockchange.html?n=137&year=2011
|
123
|
-
def test_historical_time_change_in_la_backward
|
124
|
-
timezone = Timezone::Zone.new zone: 'America/Los_Angeles'
|
125
|
-
local = Time.strptime('2011-11-06T01:59:59 UTC', '%Y-%m-%dT%H:%M:%S %Z')
|
126
|
-
utc = Time.strptime('2011-11-06T08:59:59 UTC', '%Y-%m-%dT%H:%M:%S %Z')
|
127
|
-
assert_equal local.to_i, timezone.time(utc).to_i
|
128
|
-
|
129
|
-
timezone = Timezone::Zone.new zone: 'America/Los_Angeles'
|
130
|
-
local = Time.strptime('2011-11-06T01:00:00 UTC', '%Y-%m-%dT%H:%M:%S %Z')
|
131
|
-
utc = Time.strptime('2011-11-06T09:00:00 UTC', '%Y-%m-%dT%H:%M:%S %Z')
|
132
|
-
assert_equal local.to_i, timezone.time(utc).to_i
|
133
|
-
end
|
134
|
-
|
135
|
-
# http://www.timeanddate.com/worldclock/clockchange.html?n=2364&year=1940
|
136
|
-
def test_historical_time_change_in_hebron
|
137
|
-
timezone = Timezone::Zone.new zone: 'Asia/Hebron'
|
138
|
-
local = Time.strptime('1940-05-31T23:59:59 UTC', '%Y-%m-%dT%H:%M:%S %Z')
|
139
|
-
utc = Time.strptime('1940-05-31T21:59:59 UTC', '%Y-%m-%dT%H:%M:%S %Z')
|
140
|
-
assert_equal local.to_i, timezone.time(utc).to_i
|
141
|
-
|
142
|
-
timezone = Timezone::Zone.new zone: 'Asia/Hebron'
|
143
|
-
local = Time.strptime('1940-06-01T01:00:00 UTC', '%Y-%m-%dT%H:%M:%S %Z')
|
144
|
-
utc = Time.strptime('1940-05-31T22:00:00 UTC', '%Y-%m-%dT%H:%M:%S %Z')
|
145
|
-
assert_equal local.to_i, timezone.time(utc).to_i
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_loading_half_hour_timezone
|
149
|
-
timezone = Timezone::Zone.new zone: 'Asia/Kathmandu'
|
150
|
-
utc = Time.utc(2011, 1, 4, 3, 51, 29)
|
151
|
-
local = Time.utc(2011, 1, 4, 9, 36, 29)
|
152
|
-
assert_equal local.to_i, timezone.time(utc).to_i
|
153
|
-
end
|
154
|
-
|
155
|
-
# Testing is done with strings since two times can be equivalent even if
|
156
|
-
# their offsets do not match, and we want to test that the time and offsets
|
157
|
-
# are equivalent.
|
158
|
-
def test_time_with_offset
|
159
|
-
timezone = Timezone::Zone.new zone: 'Asia/Kathmandu'
|
160
|
-
utc = Time.utc(2011, 1, 4, 3, 51, 29)
|
161
|
-
local = Time.new(2011, 1, 4, 9, 36, 29, 20_700)
|
162
|
-
assert_equal local.to_s, timezone.time_with_offset(utc).to_s
|
163
|
-
|
164
|
-
zone = Timezone::Zone.new(zone: 'America/Los_Angeles')
|
165
|
-
utc = Time.utc(2014, 12, 15, 22, 00, 00)
|
166
|
-
local = Time.new(2014, 12, 15, 14, 00, 00, '-08:00')
|
167
|
-
assert_equal local.to_s, zone.time_with_offset(utc).to_s
|
168
|
-
|
169
|
-
utc = Time.utc(2014, 4, 5, 22, 00, 00)
|
170
|
-
local = Time.new(2014, 4, 5, 15, 00, 00, '-07:00')
|
171
|
-
assert_equal local.to_s, zone.time_with_offset(utc).to_s
|
172
|
-
end
|
173
|
-
|
174
|
-
def test_australian_timezone_with_dst
|
175
|
-
timezone = Timezone::Zone.new zone: 'Australia/Adelaide'
|
176
|
-
utc = Time.utc(2010, 12, 23, 19, 37, 15)
|
177
|
-
local = Time.utc(2010, 12, 24, 6, 7, 15)
|
178
|
-
assert_equal local.to_i, timezone.time(utc).to_i
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_local_to_utc
|
182
|
-
timezone = Timezone::Zone.new(zone: 'America/Los_Angeles')
|
183
|
-
|
184
|
-
# Time maps to two rules - we pick the first
|
185
|
-
local = Time.utc(2015, 11, 1, 1, 50, 0)
|
186
|
-
utc = Time.utc(2015, 11, 1, 8, 50, 0)
|
187
|
-
assert_equal(utc.to_s, timezone.local_to_utc(local).to_s)
|
188
|
-
|
189
|
-
# Time is above the maximum - we pick the last rule
|
190
|
-
local = Time.utc(3000, 1, 1, 0, 0, 0)
|
191
|
-
utc = Time.utc(3000, 1, 1, 8, 0, 0)
|
192
|
-
assert_equal(utc.to_s, timezone.local_to_utc(local).to_s)
|
193
|
-
|
194
|
-
# Time maps to a single rule - we pick that rule
|
195
|
-
local = Time.utc(2015, 11, 1, 0, 1, 0)
|
196
|
-
utc = Time.utc(2015, 11, 1, 7, 1, 0)
|
197
|
-
assert_equal(utc.to_s, timezone.local_to_utc(local).to_s)
|
198
|
-
|
199
|
-
# Time is missing - we pick the first closest rule
|
200
|
-
local = Time.utc(2015, 3, 8, 2, 50, 0)
|
201
|
-
utc = Time.utc(2015, 3, 8, 9, 50, 0)
|
202
|
-
assert_equal(utc.to_s, timezone.local_to_utc(local).to_s)
|
203
|
-
end
|
204
|
-
|
205
|
-
def test_configure_url_default
|
206
|
-
Timezone::Configure.begin { |c| c.google_api_key = nil }
|
207
|
-
assert_equal 'api.geonames.org', Timezone::Configure.url
|
208
|
-
end
|
209
|
-
|
210
|
-
def test_configure_url_custom
|
211
|
-
Timezone::Configure.begin { |c| c.google_api_key = nil }
|
212
|
-
Timezone::Configure.begin do |c|
|
213
|
-
c.geonames_url = 'www.newtimezoneserver.com'
|
214
|
-
end
|
215
|
-
assert_equal 'www.newtimezoneserver.com', Timezone::Configure.url
|
216
|
-
# clean up url after test
|
217
|
-
Timezone::Configure.begin { |c| c.geonames_url = nil }
|
218
|
-
end
|
219
|
-
|
220
|
-
def test_utc_offset_without_dst
|
221
|
-
timezone = Timezone::Zone.new zone: 'Europe/Helsinki'
|
222
|
-
# just before DST starts
|
223
|
-
utc = Time.utc(2012, 3, 25, 0, 59, 59)
|
224
|
-
assert_equal timezone.utc_offset(utc), 7200
|
225
|
-
# on the second DST ends
|
226
|
-
utc = Time.utc(2012, 10, 28, 1, 0, 0)
|
227
|
-
assert_equal timezone.utc_offset(utc), 7200
|
228
|
-
end
|
229
|
-
|
230
|
-
def test_utc_offset_with_dst
|
231
|
-
timezone = Timezone::Zone.new zone: 'Europe/Helsinki'
|
232
|
-
# on the second DST starts
|
233
|
-
utc = Time.utc(2012, 3, 25, 1, 0, 0)
|
234
|
-
assert_equal timezone.utc_offset(utc), 10_800
|
235
|
-
# right before DST end
|
236
|
-
utc = Time.utc(2012, 10, 28, 0, 59, 59)
|
237
|
-
assert_equal timezone.utc_offset(utc), 10_800
|
238
|
-
end
|
239
|
-
|
240
|
-
def test_active_support_timezone
|
241
|
-
timezone = Timezone::Zone.new(zone: 'Australia/Adelaide')
|
242
|
-
assert_equal 'Australia/Adelaide', timezone.zone
|
243
|
-
assert_equal 'Adelaide', timezone.active_support_time_zone
|
244
|
-
|
245
|
-
timezone = Timezone::Zone.new(zone: 'America/Phoenix')
|
246
|
-
assert_equal 'America/Phoenix', timezone.zone
|
247
|
-
assert_equal 'Arizona', timezone.active_support_time_zone
|
248
|
-
|
249
|
-
timezone = Timezone::Zone.new(zone: 'America/Anchorage')
|
250
|
-
assert_equal 'America/Anchorage', timezone.zone
|
251
|
-
assert_equal 'America/Anchorage', timezone.active_support_time_zone
|
252
|
-
end
|
253
|
-
|
254
|
-
EQUIVALENCE_METHODS = [
|
255
|
-
:time,
|
256
|
-
:local_to_utc,
|
257
|
-
:time_with_offset,
|
258
|
-
:dst?,
|
259
|
-
:utc_offset
|
260
|
-
].freeze
|
261
|
-
|
262
|
-
def check_equivalence(zone, time, other)
|
263
|
-
tz = Timezone::Zone.new(zone: zone)
|
264
|
-
|
265
|
-
EQUIVALENCE_METHODS.each do |m|
|
266
|
-
assert_equal(tz.public_send(m, time), tz.public_send(m, other))
|
267
|
-
end
|
268
|
-
end
|
269
|
-
|
270
|
-
def test_date_equivalence
|
271
|
-
time = Time.new(2011, 2, 3, 0, 0, 0)
|
272
|
-
date = Date.new(2011, 2, 3)
|
273
|
-
|
274
|
-
check_equivalence('America/Los_Angeles', time, date)
|
275
|
-
|
276
|
-
time = Time.new(2011, 6, 3, 0, 0, 0)
|
277
|
-
date = Date.new(2011, 6, 3)
|
278
|
-
|
279
|
-
check_equivalence('America/Los_Angeles', time, date)
|
280
|
-
end
|
281
|
-
|
282
|
-
def test_datetime_equivalence
|
283
|
-
zone = ENV['TZ']
|
284
|
-
ENV['TZ'] = 'UTC'
|
285
|
-
time = Time.new(2011, 2, 3, 13, 5, 0)
|
286
|
-
datetime = DateTime.new(2011, 2, 3, 13, 5, 0, 0)
|
287
|
-
|
288
|
-
check_equivalence('America/Los_Angeles', time, datetime)
|
289
|
-
|
290
|
-
time = Time.new(2011, 6, 3, 13, 5, 0)
|
291
|
-
datetime = DateTime.new(2011, 6, 3, 13, 5, 0, 0)
|
292
|
-
|
293
|
-
check_equivalence('America/Los_Angeles', time, datetime)
|
294
|
-
ensure
|
295
|
-
ENV['TZ'] = zone
|
296
|
-
end
|
297
|
-
end
|