timezone 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +1 -1
- data/CHANGES.markdown +6 -0
- data/lib/timezone/version.rb +1 -1
- data/lib/timezone/zone.rb +14 -0
- data/test/timezone_test.rb +40 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fb2ccb43fbad42a105270baf016dee990f3c5d9
|
4
|
+
data.tar.gz: f72e8df98c7261ccdef15ea14a4b660e6f877a8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28391163d770b63a803d9d2114156e1550d08e5652af45cde75ee4cc6204852908e65a614f34044eaefceb4da677d58c466d024f290a60b8304247b3b7de191f
|
7
|
+
data.tar.gz: aec09d26909656631909b53db3440c6f04af0f8b12f541f66a962a891de3a5c94400b62e7e7b84a539ae71325cc73a8e225c69c4f285e152fb21dee8babd15d4
|
data/.rubocop_todo.yml
CHANGED
data/CHANGES.markdown
CHANGED
data/lib/timezone/version.rb
CHANGED
data/lib/timezone/zone.rb
CHANGED
@@ -55,6 +55,8 @@ module Timezone
|
|
55
55
|
# offset in the timezone rules. Once the offset has been found that offset is added to the reference UTC time
|
56
56
|
# to calculate the reference time in the timezone.
|
57
57
|
def time(reference)
|
58
|
+
reference = sanitize(reference)
|
59
|
+
|
58
60
|
reference.utc + utc_offset(reference)
|
59
61
|
end
|
60
62
|
|
@@ -69,6 +71,8 @@ module Timezone
|
|
69
71
|
# separate UTC times (during a fall back). All of these cases are ignored here and the best
|
70
72
|
# (first) guess is used instead.
|
71
73
|
def local_to_utc(time)
|
74
|
+
time = sanitize(time)
|
75
|
+
|
72
76
|
time.utc - rule_for_local(time).rules.first[OFFSET_BIT]
|
73
77
|
end
|
74
78
|
|
@@ -84,6 +88,8 @@ module Timezone
|
|
84
88
|
# to calculate the reference time in the timezone. The offset is then
|
85
89
|
# appended to put the time object into the proper offset.
|
86
90
|
def time_with_offset(reference)
|
91
|
+
reference = sanitize(reference)
|
92
|
+
|
87
93
|
utc = time(reference)
|
88
94
|
offset = utc_offset(reference)
|
89
95
|
Time.new(utc.year, utc.month, utc.day, utc.hour, utc.min, utc.sec, offset)
|
@@ -91,6 +97,8 @@ module Timezone
|
|
91
97
|
|
92
98
|
# Whether or not the time in the timezone is in DST.
|
93
99
|
def dst?(reference)
|
100
|
+
reference = sanitize(reference)
|
101
|
+
|
94
102
|
rule_for_utc(reference)[DST_BIT]
|
95
103
|
end
|
96
104
|
|
@@ -98,6 +106,8 @@ module Timezone
|
|
98
106
|
#
|
99
107
|
# timezone.utc_offset(reference)
|
100
108
|
def utc_offset(reference=Time.now)
|
109
|
+
reference = sanitize(reference)
|
110
|
+
|
101
111
|
rule_for_utc(reference)[OFFSET_BIT]
|
102
112
|
end
|
103
113
|
|
@@ -142,6 +152,10 @@ module Timezone
|
|
142
152
|
|
143
153
|
private
|
144
154
|
|
155
|
+
def sanitize(reference)
|
156
|
+
reference.to_time
|
157
|
+
end
|
158
|
+
|
145
159
|
# Does the given time (in seconds) match this rule?
|
146
160
|
#
|
147
161
|
# Each rule has a SOURCE bit which is the number of seconds, since the
|
data/test/timezone_test.rb
CHANGED
@@ -249,4 +249,44 @@ class TimezoneTest < ::Minitest::Unit::TestCase
|
|
249
249
|
assert_equal 'America/Anchorage', timezone.zone
|
250
250
|
assert_equal 'America/Anchorage', timezone.active_support_time_zone
|
251
251
|
end
|
252
|
+
|
253
|
+
EQUIVALENCE_METHODS = [
|
254
|
+
:time,
|
255
|
+
:local_to_utc,
|
256
|
+
:time_with_offset,
|
257
|
+
:dst?,
|
258
|
+
:utc_offset
|
259
|
+
]
|
260
|
+
|
261
|
+
def check_equivalence(zone, time, other)
|
262
|
+
tz = Timezone::Zone.new(:zone => zone)
|
263
|
+
|
264
|
+
EQUIVALENCE_METHODS.each do |m|
|
265
|
+
assert_equal(tz.public_send(m, time), tz.public_send(m, other))
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_date_equivalence
|
270
|
+
time = Time.new(2011, 2, 3, 0, 0, 0)
|
271
|
+
date = Date.new(2011, 2, 3)
|
272
|
+
|
273
|
+
check_equivalence('America/Los_Angeles', time, date)
|
274
|
+
|
275
|
+
time = Time.new(2011, 6, 3, 0, 0, 0)
|
276
|
+
date = Date.new(2011, 6, 3)
|
277
|
+
|
278
|
+
check_equivalence('America/Los_Angeles', time, date)
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_datetime_equivalence
|
282
|
+
time = Time.new(2011, 2, 3, 13, 5, 0)
|
283
|
+
datetime = DateTime.new(2011, 2, 3, 13, 5, 0)
|
284
|
+
|
285
|
+
check_equivalence('America/Los_Angeles', time, datetime)
|
286
|
+
|
287
|
+
time = Time.new(2011, 6, 3, 13, 5, 0)
|
288
|
+
datetime = DateTime.new(2011, 6, 3, 13, 5, 0)
|
289
|
+
|
290
|
+
check_equivalence('America/Los_Angeles', time, datetime)
|
291
|
+
end
|
252
292
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timezone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pan Thomakos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -735,10 +735,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
735
735
|
version: '0'
|
736
736
|
requirements: []
|
737
737
|
rubyforge_project: timezone
|
738
|
-
rubygems_version: 2.
|
738
|
+
rubygems_version: 2.4.5.1
|
739
739
|
signing_key:
|
740
740
|
specification_version: 4
|
741
|
-
summary: timezone-0.
|
741
|
+
summary: timezone-0.5.0
|
742
742
|
test_files:
|
743
743
|
- test/basic_lookup_test.rb
|
744
744
|
- test/data/Helsinki_rules_without_timestamps.json
|