time-zone 1.0.0 → 1.1.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
  SHA256:
3
- metadata.gz: c45f75eb9cc62be35e1a2ab9a07932bcd26a82fe3b256f6da69a4d8fe436d961
4
- data.tar.gz: 541336a54e240c1b6f65955f764c08adaaa4a772eeb73fb7c5e38ef1e10f0072
3
+ metadata.gz: e87828391a79bc472c63dabacbb85b98438e428c396506114e74188608710a82
4
+ data.tar.gz: aa45a0f8fc9ef29e3dafe0e4b090f1b999e0d0f98c071b147c9fa014eae4030b
5
5
  SHA512:
6
- metadata.gz: d6e8d0229d3a43912e324ddb4c9cf312d9384af9af7c3e76bd19631a1eb0ca9ce40c284cace46cd70324746fc421192d2f8974aee617254500e2443580325164
7
- data.tar.gz: 6063d30135ae3c588bf10e62891ce1a10b0fd875d26de7052953bcf2035b167ac8fca9c8fe8fbb0c7dad945c2684851f63ae397ad8982c18674cb3c6b8ee0454
6
+ metadata.gz: 6c547d0b8324fa6120e152869a395b9658dbc07a5c5556886efc1ee7664b88af481ad7b086654b11d85d505ca8b55885c6638b0da21bc51d653e0410c561a31d
7
+ data.tar.gz: a1bad96bd14f8932432ef9349573b5e00badd6c075ba305ecb8451fba404fd5064273bfa5179d6d9c945a2000b4e2ced0b97fc192f5c0bab83487a041622b0c1
@@ -17,6 +17,10 @@ rvm:
17
17
  - jruby-head
18
18
  - ruby-head
19
19
 
20
+ env:
21
+ - TZ=UTC
22
+ - TZ=Pacific/Auckland
23
+
20
24
  # Setup the compilers:
21
25
  matrix:
22
26
  allow_failures:
@@ -30,12 +30,18 @@ class Time
30
30
  end
31
31
  end
32
32
 
33
- def self.zone(zone)
33
+ def self.zone
34
34
  LOCK.synchronize do
35
35
  ENV['TZ']
36
36
  end
37
37
  end
38
38
 
39
+ UTC = "UTC".freeze
40
+
41
+ def self.utc?
42
+ zone == UTC
43
+ end
44
+
39
45
  def self.with(zone)
40
46
  LOCK.synchronize do
41
47
  original_zone = ENV['TZ']
@@ -38,7 +38,7 @@ class Time
38
38
  end
39
39
 
40
40
  def self.from(time, zone)
41
- self.new(time.year, time.month, time.day, time.hour, time.min, time.sec, zone)
41
+ self.new(time.year, time.month, time.day, time.hour, time.minute, time.second, zone)
42
42
  end
43
43
 
44
44
  def self.parse(*args)
@@ -69,7 +69,11 @@ class Time
69
69
  self.class.from(Time::Zone.convert(to_time, zone), zone)
70
70
  end
71
71
 
72
- private def with_offset(months, seconds = 0)
72
+ # Generate a new time with the specified changes.
73
+ # @param months [Numeric] add this many months
74
+ # @param seconds [Numeric] add this many seconds
75
+ # @param zone [String] forcefully change the timezone without doing any conversion.
76
+ def with_offset(months = 0, seconds = 0, zone = @zone)
73
77
  current = self
74
78
 
75
79
  if months != 0
@@ -77,10 +81,11 @@ class Time
77
81
  end
78
82
 
79
83
  if seconds != 0
80
- current = current.to_time + seconds
84
+ # https://bugs.ruby-lang.org/issues/14879
85
+ current = Time::Zone.convert(current.to_time + seconds, @zone)
81
86
  end
82
87
 
83
- self.class.from(current, @zone)
88
+ self.class.from(current, zone)
84
89
  end
85
90
 
86
91
  # Add duration in various units.
@@ -20,6 +20,6 @@
20
20
 
21
21
  class Time
22
22
  module Zone
23
- VERSION = "1.0.0"
23
+ VERSION = "1.1.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time-zone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams