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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f91fb2c17c8b8a03e18f1867cbbc561f39bbfa2c
4
- data.tar.gz: bc255d696fb86617af8873c64906b8bc8b7cd3fc
3
+ metadata.gz: 8fb2ccb43fbad42a105270baf016dee990f3c5d9
4
+ data.tar.gz: f72e8df98c7261ccdef15ea14a4b660e6f877a8c
5
5
  SHA512:
6
- metadata.gz: 1bbdefc95abeaebedf6d8987f030c6bca5a71471cfd3db70567fdfb18c6dda0b803b2b9546a3c46f15c2a89af3aa866e4f5701d45f68aefeb2b65f3d684fd3fa
7
- data.tar.gz: ece0fb0d7da9b3f52a02f6aa2834fbc282ce9ae0eb53679c0bba6c2d52d02b4e0375ee8b8fa278b336cad15a5962cf455206b86a8eabe163996ebc85e74b3725
6
+ metadata.gz: 28391163d770b63a803d9d2114156e1550d08e5652af45cde75ee4cc6204852908e65a614f34044eaefceb4da677d58c466d024f290a60b8304247b3b7de191f
7
+ data.tar.gz: aec09d26909656631909b53db3440c6f04af0f8b12f541f66a962a891de3a5c94400b62e7e7b84a539ae71325cc73a8e225c69c4f285e152fb21dee8babd15d4
@@ -22,7 +22,7 @@ Metrics/AbcSize:
22
22
  # Offense count: 3
23
23
  # Configuration parameters: CountComments.
24
24
  Metrics/ClassLength:
25
- Max: 190
25
+ Max: 219
26
26
 
27
27
  # Offense count: 32
28
28
  # Configuration parameters: AllowURI, URISchemes.
@@ -1,3 +1,9 @@
1
+ # Unreleased (master)
2
+
3
+ # 0.5.0
4
+
5
+ * Added support for `DateTime` and `Date` objects. (panthomakos)
6
+
1
7
  # 0.4.3
2
8
 
3
9
  * Updated with tzdata-2015g-1. (panthomakos)
@@ -1,3 +1,3 @@
1
1
  module Timezone
2
- VERSION = "0.4.3"
2
+ VERSION = '0.5.0'
3
3
  end
@@ -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
@@ -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.3
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-10-12 00:00:00.000000000 Z
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.2.3
738
+ rubygems_version: 2.4.5.1
739
739
  signing_key:
740
740
  specification_version: 4
741
- summary: timezone-0.4.3
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