ozone 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/ozone/version.rb +1 -1
- data/lib/ozone.rb +29 -36
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98d2324e166daa336808e183a8d594f0b18e4cb3
|
4
|
+
data.tar.gz: 2d0b60a51b1d5d5f2a3547a311cb4247476513f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
data/lib/ozone.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
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
|
-
|
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 <=>
|
40
|
-
|
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
|
-
|
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
|
-
|
41
|
+
protected
|
66
42
|
|
67
43
|
def adjusted_time
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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.
|
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-
|
11
|
+
date: 2015-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|