timing 0.1.3 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +48 -1
- data/lib/timing/hour_minutes_seconds.rb +78 -0
- data/lib/timing/time_in_zone.rb +1 -1
- data/lib/timing/version.rb +1 -1
- data/lib/timing.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b759b410d5c8ac1cbdbbe5868ebbceab9a7a11a8b5e8edba0678a1336e5c0de
|
4
|
+
data.tar.gz: 58cf565f2bbcf85484940e33906ab03418d4fd04ad191cd85edc25f8dde6c149
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fbc1aa7065242e4354ddf4275dea30b228e526a116dcc7e7ae8db73e8dc10b4181d5618d965b26837e86dabbeac65e396441e1db7bbbe73a2cf474a68f7b80b
|
7
|
+
data.tar.gz: 131b24b4d1b443d1c4ed35e0adcf4ab99c211dad29d4d9ac1b218f299280f4afa924dfb387e597901b39fe706dacfec8fdfc49eb88428e9f287bb1ca2893ebb9
|
data/README.md
CHANGED
@@ -94,6 +94,7 @@ Timing::NaturalTimeLanguage.parse 'now'
|
|
94
94
|
```
|
95
95
|
|
96
96
|
Named moments
|
97
|
+
```
|
97
98
|
- now
|
98
99
|
- Now -0500
|
99
100
|
- today
|
@@ -101,37 +102,47 @@ Named moments
|
|
101
102
|
- Today -0600
|
102
103
|
- yesterday -0400
|
103
104
|
- tomorrow -0300
|
105
|
+
```
|
104
106
|
|
105
107
|
Last/Next day name
|
108
|
+
```
|
106
109
|
- last Monday +0200
|
107
110
|
- last fri +0100
|
108
111
|
- next tuesday +0000
|
109
112
|
- next sat -0100
|
110
113
|
- last thursday including today -0300
|
111
114
|
- next mon including today +0200
|
115
|
+
```
|
112
116
|
|
113
117
|
Date (at 00:00:00)
|
118
|
+
```
|
114
119
|
- 6 April
|
115
120
|
- 14 Jul 2010 +0400
|
116
121
|
- 2015-09-03
|
117
122
|
- 2015-06-20 -0800
|
118
|
-
|
123
|
+
```
|
124
|
+
|
119
125
|
Beginning/End of interval
|
126
|
+
```
|
120
127
|
- Beginning of month
|
121
128
|
- end of year +0700
|
122
129
|
- beginning of week
|
123
130
|
- End of Day -0100
|
124
131
|
- end of hour +0400
|
132
|
+
```
|
125
133
|
|
126
134
|
Time ago (now - interval)
|
135
|
+
```
|
127
136
|
- 1 minute ago
|
128
137
|
- 3 hours ago -0500
|
129
138
|
- 5 days ago -0100
|
130
139
|
- 4 weeks ago +0100
|
131
140
|
- 10 months ago +0330
|
132
141
|
- 7 years ago -0700
|
142
|
+
```
|
133
143
|
|
134
144
|
Date at time
|
145
|
+
```
|
135
146
|
- today at 15:40
|
136
147
|
- last sunday at 08:43:21 -0300
|
137
148
|
- yesterday at beginning
|
@@ -142,8 +153,10 @@ Date at time
|
|
142
153
|
- 2001-07-14 at 18:41
|
143
154
|
- 2012-08-17 14:35:20
|
144
155
|
- 1980-04-21T08:15:03-0500
|
156
|
+
```
|
145
157
|
|
146
158
|
Before/After moment
|
159
|
+
```
|
147
160
|
- 15 minutes from now
|
148
161
|
- 3 days before yesterday
|
149
162
|
- 1 month from today
|
@@ -152,6 +165,40 @@ Before/After moment
|
|
152
165
|
- 1 month before beginning of month
|
153
166
|
- 1 year before 9 Sep +0300
|
154
167
|
- 2 years from 2001-05-21T12:30:40 -0500
|
168
|
+
```
|
169
|
+
|
170
|
+
|
171
|
+
#### HourMinutesSeconds
|
172
|
+
|
173
|
+
Hour, minutes and seconds model.
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
HourMinutesSeconds.new 9, 23, 41 # => 09:23:41
|
177
|
+
HourMinutesSeconds.new 9, 23 # => 09:23:00
|
178
|
+
HourMinutesSeconds.new 9 # => 09:23:00
|
179
|
+
|
180
|
+
hhmmss = HourMinutesSeconds.parse '9:23:41'
|
181
|
+
hhmmss.hour # => 9
|
182
|
+
hhmmss.minutes # => 23
|
183
|
+
hhmmss.seconds # => 41
|
184
|
+
hhmmss.iso8601 # => 09:23:41
|
185
|
+
```
|
186
|
+
|
187
|
+
|
188
|
+
#### ZoneOffset
|
189
|
+
|
190
|
+
Seconds wrapper helper for utc offset
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
Timing::ZoneOffset.new -10800 # => -0300 (-10800.0)
|
194
|
+
Timing::ZoneOffset.new 21600 # => +0600 (21600.0)
|
195
|
+
|
196
|
+
Timing::ZoneOffset.parse '-0300' # => -0300 (-10800.0)
|
197
|
+
Timing::ZoneOffset.parse '+0600' # => +0600 (21600.0)
|
198
|
+
|
199
|
+
zone_offset = Timing::ZoneOffset.parse '-0300'
|
200
|
+
zone_offset.iso8601 # => '-03:00'
|
201
|
+
```
|
155
202
|
|
156
203
|
## Contributing
|
157
204
|
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Timing
|
2
|
+
class HourMinutesSeconds
|
3
|
+
|
4
|
+
HH_MM_SS_REGEX = /^(?<hour>\d{1,2})(:(?<minutes>\d{1,2}))?(:(?<seconds>\d{1,2}))?$/
|
5
|
+
|
6
|
+
attr_reader :hour, :minutes, :seconds
|
7
|
+
|
8
|
+
def initialize(hour, minutes=0, seconds=0)
|
9
|
+
raise ArgumentError, "Invalid hour #{hour}" if !hour.is_a?(Integer) || hour < 0 || hour > 23
|
10
|
+
raise ArgumentError, "Invalid minutes #{minutes}" if !minutes.is_a?(Integer) || minutes < 0 || minutes > 59
|
11
|
+
raise ArgumentError, "Invalid minutes #{seconds}" if !seconds.is_a?(Integer) || seconds < 0 || seconds > 59
|
12
|
+
|
13
|
+
@hour = hour
|
14
|
+
@minutes = minutes
|
15
|
+
@seconds = seconds
|
16
|
+
end
|
17
|
+
|
18
|
+
def iso8601
|
19
|
+
[hour, minutes, seconds].map { |d| d.to_s.rjust(2, '0') }.join(':')
|
20
|
+
end
|
21
|
+
alias_method :to_s, :iso8601
|
22
|
+
alias_method :inspect, :iso8601
|
23
|
+
|
24
|
+
def ==(other)
|
25
|
+
other.kind_of?(self.class) && hash == other.hash
|
26
|
+
end
|
27
|
+
alias_method :eql?, :==
|
28
|
+
|
29
|
+
def hash
|
30
|
+
[hour, minutes, seconds].hash
|
31
|
+
end
|
32
|
+
|
33
|
+
def >(other)
|
34
|
+
raise ArgumentError, "Invalid argument #{other}" unless other.is_a?(HourMinutesSeconds)
|
35
|
+
|
36
|
+
(hour > other.hour) ||
|
37
|
+
(hour == other.hour && minutes > other.minutes) ||
|
38
|
+
(hour == other.hour && minutes == other.minutes && seconds > other.seconds)
|
39
|
+
end
|
40
|
+
|
41
|
+
def <(other)
|
42
|
+
raise ArgumentError, "Invalid argument #{other}" unless other.is_a?(HourMinutesSeconds)
|
43
|
+
|
44
|
+
(hour < other.hour) ||
|
45
|
+
(hour == other.hour && minutes < other.minutes) ||
|
46
|
+
(hour == other.hour && minutes == other.minutes && seconds < other.seconds)
|
47
|
+
end
|
48
|
+
|
49
|
+
def >=(other)
|
50
|
+
self > other || self == other
|
51
|
+
end
|
52
|
+
|
53
|
+
def <=(other)
|
54
|
+
self < other || self == other
|
55
|
+
end
|
56
|
+
|
57
|
+
def <=>(other)
|
58
|
+
if self == other
|
59
|
+
0
|
60
|
+
elsif self > other
|
61
|
+
1
|
62
|
+
else
|
63
|
+
-1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def between?(from, to)
|
68
|
+
self >= from && self <= to
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.parse(expression)
|
72
|
+
match = expression.to_s.match HH_MM_SS_REGEX
|
73
|
+
raise ArgumentError, "Invalid expression #{expression}" unless match
|
74
|
+
new(*match.names.map { |n| (match[n] || 0).to_i })
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
data/lib/timing/time_in_zone.rb
CHANGED
@@ -6,7 +6,7 @@ module Timing
|
|
6
6
|
REGEXP = /[+-]\d\d:?\d\d$/
|
7
7
|
|
8
8
|
def_delegators :time, :to_i, :to_f, :to_date, :to_datetime, :between?, :==, :<, :<=, :>, :>=, :<=>, :hash
|
9
|
-
def_delegators :time_with_offset, :year, :month, :day, :hour, :min, :sec, :wday, :yday
|
9
|
+
def_delegators :time_with_offset, :year, :month, :day, :hour, :min, :sec, :wday, :yday, :sunday?, :monday?, :tuesday?, :wednesday?, :thursday?, :friday?, :saturday?
|
10
10
|
|
11
11
|
attr_reader :zone_offset
|
12
12
|
|
data/lib/timing/version.rb
CHANGED
data/lib/timing.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treetop
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- Rakefile
|
169
169
|
- lib/timing.rb
|
170
170
|
- lib/timing/helpers.rb
|
171
|
+
- lib/timing/hour_minutes_seconds.rb
|
171
172
|
- lib/timing/interval.rb
|
172
173
|
- lib/timing/natural_time_language.rb
|
173
174
|
- lib/timing/natural_time_language.treetop
|