ozone 0.2.1 → 0.3.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -0
  3. data/lib/ozone/version.rb +1 -1
  4. data/lib/ozone.rb +29 -36
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c585fbf22c931b863f9fddcdf007c5ae2fc4f92
4
- data.tar.gz: fe8603a322ab57aa36896ee45a5575bebee510b0
3
+ metadata.gz: 98d2324e166daa336808e183a8d594f0b18e4cb3
4
+ data.tar.gz: 2d0b60a51b1d5d5f2a3547a311cb4247476513f2
5
5
  SHA512:
6
- metadata.gz: 9ee36d054417a3cbc4f9a79e3b746d64739933bdb6c3b36fd8e592f2572c01ec20162bba2513acacb5f75ce89833d973cfe20d24affca7598af9f4450395c826
7
- data.tar.gz: b205d566b1da27dcb1bc3df74511af671bee64c63e174371f1e0f5be64b1ef6e2c123e54a65d973810bee9454752a26be0339216fa51734cacc32ccd69a440de
6
+ metadata.gz: 1949c0b5bc446edbd87fcc33be20d49c841fcc263864d0f7b187d06a5f93075e7a8a487c325f9c1b142dab6a40db1211b521a91e93f9da3a43d69c593df36fc0
7
+ data.tar.gz: c00a22953650d7de68a9c1c0f60aaa733b06176824648a2c5dda7582aa91d0bdb266846787d75514b2b93b90a999362ee6b6b0ea0cbfd4f6f7f4ee1416143de2
data/README.md CHANGED
@@ -74,6 +74,8 @@ Ozone::Formatter has one method -- call -- which takes a time, offset (from utc,
74
74
 
75
75
  This functionality can also be accessed via the Ozone::Time#strftime method.
76
76
 
77
+ ### NOTE: Since all operations are executing in UTC time, the time zone in the format string will *always* be UTC
78
+
77
79
  ## Development
78
80
 
79
81
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/ozone/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ozone
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/ozone.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "ozone/version"
1
+ require 'ozone/version'
2
2
 
3
3
  require 'active_support/time'
4
4
 
@@ -7,68 +7,61 @@ module Ozone
7
7
  module_function
8
8
 
9
9
  def call(time:, offset:, observes_dst: true, format: '%Y-%m-%d %H:%M')
10
- timezone = ActiveSupport::TimeZone[offset/60]
11
- time_with_zone = time.in_time_zone(timezone)
12
- if time_with_zone.dst? && !observes_dst
13
- # If we're during daylight savings time, but
14
- # we are not observing daylight savings,
15
- # there is a one-hour window where there is not
16
- # an equivalent time between standard and daylight
17
- # savings times. In order to deal with this,
18
- # we subtract two hours from the offset and then
19
- # take 2 hours from the given time. This frees
20
- # us to string format the time without ruby
21
- # making adjustments internally.
22
- offset -= 120
23
- timezone = ActiveSupport::TimeZone[offset/60]
24
- 2.hours.since(time.in_time_zone(timezone)).strftime(format)
25
- else
26
- time_with_zone.strftime(format)
27
- end
10
+ ::Ozone::Time.new(time: time, offset: offset, observes_dst: observes_dst).strftime(format: format)
28
11
  end
29
12
  end
30
13
 
31
14
  class Time
32
15
  def initialize(time:, offset:, observes_dst: true)
33
16
  @offset = offset
34
- @timezone = ActiveSupport::TimeZone[offset/60]
35
17
  @observes_dst = observes_dst
36
18
  @time = time
37
19
  end
38
20
 
39
- def <=> (time_with_zone)
40
- if after?(time_with_zone)
41
- 1
42
- elsif before?(time_with_zone)
43
- -1
44
- else
45
- 0
46
- end
21
+ def <=>(time_with_zone)
22
+ adjusted_time <=> to_ozone_time(time_with_zone).adjusted_time
47
23
  end
48
24
 
49
25
  def before?(time_with_zone)
50
- adjusted_time < time_with_zone
26
+ adjusted_time < to_ozone_time(time_with_zone).adjusted_time
51
27
  end
52
28
 
53
29
  def after?(time_with_zone)
54
- adjusted_time > time_with_zone
30
+ adjusted_time > to_ozone_time(time_with_zone).adjusted_time
55
31
  end
56
32
 
57
33
  def strftime(format: '%Y-%m-%d %H:%M')
58
- Formatter.call(time: @time, offset: @offset, observes_dst: @observes_dst, format: format)
34
+ adjusted_time.strftime(format)
59
35
  end
60
36
 
61
37
  alias_method :<, :before?
62
38
  alias_method :>, :after?
63
39
  alias_method :to_s, :strftime
64
40
 
65
- private
41
+ protected
66
42
 
67
43
  def adjusted_time
68
- time_with_zone = @time.in_time_zone(@timezone)
69
- time_with_zone.dst? && !@observes_dst ?
70
- 1.hour.until(time_with_zone) :
71
- time_with_zone
44
+ offset = @offset
45
+
46
+ # Apply the DST offset if the practice observes DST and if DST is currently in effect in a timezone known to
47
+ # observe DST.
48
+ offset += 60 if @observes_dst && @time.in_time_zone(PST).dst?
49
+
50
+ if offset > 0
51
+ offset.minutes.until(@time)
52
+ elsif offset < 0
53
+ offset.minutes.since(@time)
54
+ else
55
+ @time
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ PST = ActiveSupport::TimeZone['Pacific Time (US & Canada)']
62
+
63
+ def to_ozone_time(time)
64
+ Ozone::Time.new(time: time.utc, offset: @offset, observes_dst: @observes_dst)
72
65
  end
73
66
  end
74
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ozone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hubert Huang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-03 00:00:00.000000000 Z
11
+ date: 2015-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport