schedulability 0.3.0 → 0.4.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
- checksums.yaml.gz.sig +3 -3
- data.tar.gz.sig +0 -0
- data/ChangeLog +77 -1
- data/History.md +13 -1
- data/Manifest.txt +0 -2
- data/README.md +5 -5
- data/lib/schedulability.rb +2 -2
- data/lib/schedulability/schedule.rb +5 -5
- data/spec/schedulability/schedule_spec.rb +91 -94
- metadata +24 -26
- metadata.gz.sig +2 -2
- data/lib/schedulability/mixins.rb +0 -201
- data/spec/schedulability/mixins_spec.rb +0 -164
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1480aa1c07def4a986de461321563f3eb2bdf99de8fe70491e3c3c5cb724b41
|
4
|
+
data.tar.gz: 9a30eb358c982f4b94ee384a65a0b5e4b4296a9a35c832e5a4cdd66b1eced155
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f935aba6d33b855ff36f93d4d30766513c0d6234bd42aa547a8f92e8384eee0ac8ef5082fa6c8f08d36f3682bcb5b826092974673d50fdaa8e5b411a1166c28e
|
7
|
+
data.tar.gz: bc246c803a99603dbd4ecc34b3f66f72691dd0f49e98eef4365c70e81e065be777a7f7309f6b8f711edbe139df823cebe6dad3f29e97c3f7796656b57cc54c23
|
checksums.yaml.gz.sig
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
�Z
|
3
|
-
|
1
|
+
��mj��v��kve��5j)������JK��2�
|
2
|
+
�A|o\�o��Mn���^�kq<At��M֧^p���)�"[m���*�y�j��mk,�vf��u�&����uN��'fLz�Q r�ju��>�x~���:��o�����hP��w=�e�K���M�i��ɠ�{L����~��Ǯ�\|Z���-�j��a�N�����i4�
|
3
|
+
p�f���e*����\��t�����%6/ު�{D�����S��w��Q��-��J�o Q�"�[s�N}�1)�%|��J���l� [��ܳ�s�{���x��}>x�Ir��bwh/E%�U��l�6���y���r��$�t�3W�.�.��}'uI����]PZ
|
data.tar.gz.sig
CHANGED
Binary file
|
data/ChangeLog
CHANGED
@@ -1,3 +1,79 @@
|
|
1
|
+
2018-09-12 Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
* lib/schedulability/schedule.rb:
|
4
|
+
Fix indentation warnings
|
5
|
+
[b576d8683cf1] [tip]
|
6
|
+
|
7
|
+
* .ruby-version:
|
8
|
+
Use Ruby 2.5 for development
|
9
|
+
[33f373ac276f]
|
10
|
+
|
11
|
+
2018-08-31 Mahlon E. Smith <mahlon@martini.nu>
|
12
|
+
|
13
|
+
* README.md:
|
14
|
+
Reflect reality in the README.
|
15
|
+
[cad3559428fe]
|
16
|
+
|
17
|
+
2016-10-21 Michael Granger <ged@FaerieMUD.org>
|
18
|
+
|
19
|
+
* .hgtags:
|
20
|
+
Added tag v0.3.0 for changeset cc6c1906a6a4
|
21
|
+
[62b3ca9f5313] [github/master]
|
22
|
+
|
23
|
+
* .hgsigs:
|
24
|
+
Added signature for changeset 4eb3e8287023
|
25
|
+
[cc6c1906a6a4] [v0.3.0]
|
26
|
+
|
27
|
+
* History.md, lib/schedulability.rb:
|
28
|
+
Bump the minor version and update history.
|
29
|
+
[4eb3e8287023]
|
30
|
+
|
31
|
+
2016-07-29 Meining Lu <meining@getupperhand.com>
|
32
|
+
|
33
|
+
* lib/schedulability/parser.rb, spec/schedulability/schedule_spec.rb:
|
34
|
+
[PATCH] Add support for 0th hour and 12am From
|
35
|
+
70ef3d9b003a736b26b4a57eae15393fa31516ef Mon Sep 17 00:00:00 2001
|
36
|
+
--- lib/schedulability/parser.rb | 12 +++++---
|
37
|
+
spec/schedulability/schedule_spec.rb | 57
|
38
|
+
+++++++++++++++++++++++++++++++++++- 2 files changed, 64
|
39
|
+
insertions(+), 5 deletions(-)
|
40
|
+
|
41
|
+
Closes ged/schedulability#2 (Github).
|
42
|
+
[67e0f911d188]
|
43
|
+
|
44
|
+
2016-07-20 Michael Granger <ged@FaerieMUD.org>
|
45
|
+
|
46
|
+
* .hgtags:
|
47
|
+
Added tag v0.2.0 for changeset 22dfe155d630
|
48
|
+
[fca786536ff4]
|
49
|
+
|
50
|
+
* .hgsigs:
|
51
|
+
Added signature for changeset 9332ac7ab656
|
52
|
+
[22dfe155d630] [v0.2.0]
|
53
|
+
|
54
|
+
* schedulability.gemspec:
|
55
|
+
Update gemspec
|
56
|
+
[9332ac7ab656]
|
57
|
+
|
58
|
+
* History.md, README.md, lib/schedulability.rb:
|
59
|
+
Update history, copyright, and bump minor version.
|
60
|
+
[bd7566ac26d5]
|
61
|
+
|
62
|
+
* lib/schedulability/schedule.rb:
|
63
|
+
Strip some more debug logging
|
64
|
+
[29c266cf0066]
|
65
|
+
|
66
|
+
2016-07-17 Michael Granger <ged@FaerieMUD.org>
|
67
|
+
|
68
|
+
* .gems, .ruby-gemset, .ruby-version, .rvmrc, Manifest.txt, Rakefile,
|
69
|
+
schedulability.gemspec:
|
70
|
+
Update manifest, switch to generic RVM setup.
|
71
|
+
[f1f0dfcccfa8]
|
72
|
+
|
73
|
+
* lib/schedulability/parser.rb:
|
74
|
+
Remove a bunch of spammy debug logs
|
75
|
+
[9bf76377c7b8]
|
76
|
+
|
1
77
|
2016-07-14 Jason Rogers <jacaetevha@gmail.com>
|
2
78
|
|
3
79
|
* lib/schedulability/parser.rb, spec/schedulability/schedule_spec.rb:
|
@@ -8,7 +84,7 @@
|
|
8
84
|
spec/schedulability/schedule_spec.rb | 52
|
9
85
|
++++++++++++++++++++++++++++++++++++ 2 files changed, 57
|
10
86
|
insertions(+), 3 deletions(-)
|
11
|
-
[0f59486cf040]
|
87
|
+
[0f59486cf040]
|
12
88
|
|
13
89
|
2016-07-15 Michael Granger <ged@FaerieMUD.org>
|
14
90
|
|
data/History.md
CHANGED
@@ -1,18 +1,30 @@
|
|
1
|
+
## v0.4.0 [2018-09-12] Michael Granger <ged@FaerieMUD.org>
|
2
|
+
|
3
|
+
Bugfixes:
|
4
|
+
|
5
|
+
- Remove mixins only used in the specs.
|
6
|
+
- Fix indentation warnings
|
7
|
+
- Fix README examples
|
8
|
+
|
9
|
+
|
1
10
|
## v0.3.0 [2016-07-29] Michael Granger <ged@FaerieMUD.org>
|
2
11
|
|
3
12
|
Bugfix:
|
4
|
-
|
13
|
+
|
14
|
+
- Add support for 0th hour and 12am (thanks to
|
5
15
|
Meining Lu <meining@getupperhand.com> on Github for the patch)
|
6
16
|
|
7
17
|
|
8
18
|
## v0.2.0 [2016-07-20] Michael Granger <ged@FaerieMUD.org>
|
9
19
|
|
10
20
|
Bugfixes:
|
21
|
+
|
11
22
|
- fixes for the 0th second or minute, and the 59th second
|
12
23
|
(thanks to Jason Rogers <jacaetevha@gmail.com> for the patch)
|
13
24
|
- Make Schedule#empty? take negative periods into account
|
14
25
|
|
15
26
|
Enhancements
|
27
|
+
|
16
28
|
- Add missing Schedule#overlaps? and #exclusive predicate methods.
|
17
29
|
- Add a Schedule#to_s that stringifies them back into schedule descriptions
|
18
30
|
|
data/Manifest.txt
CHANGED
@@ -7,11 +7,9 @@ README.md
|
|
7
7
|
Rakefile
|
8
8
|
lib/schedulability.rb
|
9
9
|
lib/schedulability/exceptions.rb
|
10
|
-
lib/schedulability/mixins.rb
|
11
10
|
lib/schedulability/parser.rb
|
12
11
|
lib/schedulability/schedule.rb
|
13
12
|
spec/helpers.rb
|
14
|
-
spec/schedulability/mixins_spec.rb
|
15
13
|
spec/schedulability/parser_spec.rb
|
16
14
|
spec/schedulability/schedule_spec.rb
|
17
15
|
spec/schedulability_spec.rb
|
data/README.md
CHANGED
@@ -158,10 +158,10 @@ Schedules are immutable after they're created, but they have mutator methods to
|
|
158
158
|
allow you to compose the schedule you want by combining them, or by using
|
159
159
|
mutator methods that return a changed copy of the original:
|
160
160
|
|
161
|
-
weekend = Schedulability::Schedule( "wd {Sat - Sun}" )
|
162
|
-
weekdays = Schedulability::Schedule( "wd {Mon - Fri}" )
|
163
|
-
work_hours = Schedulability::Schedule( "hour {9am - 5pm}" )
|
164
|
-
off_hours = Schedulability::Schedule( "hour {5pm - 9am}" )
|
161
|
+
weekend = Schedulability::Schedule.parse( "wd {Sat - Sun}" )
|
162
|
+
weekdays = Schedulability::Schedule.parse( "wd {Mon - Fri}" )
|
163
|
+
work_hours = Schedulability::Schedule.parse( "hour {9am - 5pm}" )
|
164
|
+
off_hours = Schedulability::Schedule.parse( "hour {5pm - 9am}" )
|
165
165
|
|
166
166
|
### Boolean operators
|
167
167
|
on_duty = weekdays | work_hours
|
@@ -233,7 +233,7 @@ used under the terms of the Perl Artistic License.
|
|
233
233
|
|
234
234
|
The rest is:
|
235
235
|
|
236
|
-
Copyright (c) 2015-
|
236
|
+
Copyright (c) 2015-2018, Michael Granger and Mahlon E. Smith
|
237
237
|
All rights reserved.
|
238
238
|
|
239
239
|
Redistribution and use in source and binary forms, with or without
|
data/lib/schedulability.rb
CHANGED
@@ -10,10 +10,10 @@ module Schedulability
|
|
10
10
|
extend Loggability
|
11
11
|
|
12
12
|
# Package version constant
|
13
|
-
VERSION = '0.
|
13
|
+
VERSION = '0.4.0'
|
14
14
|
|
15
15
|
# VCS revision
|
16
|
-
REVISION = %q$Revision:
|
16
|
+
REVISION = %q$Revision: fec56af1f0e4 $
|
17
17
|
|
18
18
|
|
19
19
|
# Loggability API -- set up a logger for Schedulability objects
|
@@ -67,7 +67,7 @@ class Schedulability::Schedule
|
|
67
67
|
|
68
68
|
return ! self.negative_periods_include?( time_obj ) &&
|
69
69
|
self.positive_periods_include?( time_obj )
|
70
|
-
|
70
|
+
end
|
71
71
|
|
72
72
|
|
73
73
|
### Returns +true+ if any of the schedule's positive periods include the
|
@@ -75,12 +75,12 @@ class Schedulability::Schedule
|
|
75
75
|
def positive_periods_include?( time )
|
76
76
|
return self.positive_periods.empty? ||
|
77
77
|
find_matching_period_for( time, self.positive_periods )
|
78
|
-
|
78
|
+
end
|
79
79
|
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
### Returns +true+ if any of the schedule's negative periods include the
|
82
|
+
### specified +time+.
|
83
|
+
def negative_periods_include?( time )
|
84
84
|
return find_matching_period_for( time, self.negative_periods )
|
85
85
|
end
|
86
86
|
|
@@ -5,11 +5,8 @@ require_relative '../helpers'
|
|
5
5
|
require 'time'
|
6
6
|
require 'timecop'
|
7
7
|
require 'schedulability/schedule'
|
8
|
-
require 'schedulability/mixins'
|
9
8
|
|
10
9
|
|
11
|
-
using Schedulability::TimeRefinements
|
12
|
-
|
13
10
|
describe Schedulability::Schedule do
|
14
11
|
|
15
12
|
before( :all ) do
|
@@ -184,11 +181,11 @@ describe Schedulability::Schedule do
|
|
184
181
|
schedule = described_class.parse( "sec {18}" )
|
185
182
|
time = Time.iso8601( '2015-12-15T12:00:18-00:00' )
|
186
183
|
|
187
|
-
expect( schedule ).to_not include( time - 2
|
188
|
-
expect( schedule ).to_not include( time - 1
|
184
|
+
expect( schedule ).to_not include( time - 2 )
|
185
|
+
expect( schedule ).to_not include( time - 1 )
|
189
186
|
expect( schedule ).to include( time )
|
190
|
-
expect( schedule ).to_not include( time + 1
|
191
|
-
expect( schedule ).to_not include( time + 2
|
187
|
+
expect( schedule ).to_not include( time + 1 )
|
188
|
+
expect( schedule ).to_not include( time + 2 )
|
192
189
|
end
|
193
190
|
|
194
191
|
|
@@ -196,11 +193,11 @@ describe Schedulability::Schedule do
|
|
196
193
|
schedule = described_class.parse( "except sec {18}" )
|
197
194
|
time = Time.iso8601( '2015-12-15T12:00:18-00:00' )
|
198
195
|
|
199
|
-
expect( schedule ).to include( time - 2
|
200
|
-
expect( schedule ).to include( time - 1
|
196
|
+
expect( schedule ).to include( time - 2 )
|
197
|
+
expect( schedule ).to include( time - 1 )
|
201
198
|
expect( schedule ).to_not include( time )
|
202
|
-
expect( schedule ).to include( time + 1
|
203
|
-
expect( schedule ).to include( time + 2
|
199
|
+
expect( schedule ).to include( time + 1 )
|
200
|
+
expect( schedule ).to include( time + 2 )
|
204
201
|
end
|
205
202
|
|
206
203
|
|
@@ -208,12 +205,12 @@ describe Schedulability::Schedule do
|
|
208
205
|
schedule = described_class.parse( "sec {10-20}" )
|
209
206
|
time = Time.iso8601( '2015-12-15T12:00:10-00:00' )
|
210
207
|
|
211
|
-
expect( schedule ).to_not include( time - 2
|
212
|
-
expect( schedule ).to_not include( time - 1
|
208
|
+
expect( schedule ).to_not include( time - 2 )
|
209
|
+
expect( schedule ).to_not include( time - 1 )
|
213
210
|
expect( schedule ).to include( time )
|
214
|
-
expect( schedule ).to include( time + 1
|
215
|
-
expect( schedule ).to include( time + 9
|
216
|
-
expect( schedule ).to_not include( time + 10
|
211
|
+
expect( schedule ).to include( time + 1 )
|
212
|
+
expect( schedule ).to include( time + 9 )
|
213
|
+
expect( schedule ).to_not include( time + 10 )
|
217
214
|
end
|
218
215
|
|
219
216
|
|
@@ -221,15 +218,15 @@ describe Schedulability::Schedule do
|
|
221
218
|
schedule = described_class.parse( "sec {45-15}" )
|
222
219
|
time = Time.iso8601( '2015-12-15T12:00:45-00:00' )
|
223
220
|
|
224
|
-
expect( schedule ).to_not include( time - 2
|
225
|
-
expect( schedule ).to_not include( time - 1
|
221
|
+
expect( schedule ).to_not include( time - 2 )
|
222
|
+
expect( schedule ).to_not include( time - 1 )
|
226
223
|
expect( schedule ).to include( time )
|
227
|
-
expect( schedule ).to include( time + 1
|
228
|
-
expect( schedule ).to include( time + 14
|
229
|
-
expect( schedule ).to include( time + 15
|
230
|
-
expect( schedule ).to include( time + 20
|
231
|
-
expect( schedule ).to include( time + 29
|
232
|
-
expect( schedule ).to_not include( time + 30
|
224
|
+
expect( schedule ).to include( time + 1 )
|
225
|
+
expect( schedule ).to include( time + 14 )
|
226
|
+
expect( schedule ).to include( time + 15 )
|
227
|
+
expect( schedule ).to include( time + 20 )
|
228
|
+
expect( schedule ).to include( time + 29 )
|
229
|
+
expect( schedule ).to_not include( time + 30 )
|
233
230
|
end
|
234
231
|
|
235
232
|
|
@@ -237,13 +234,13 @@ describe Schedulability::Schedule do
|
|
237
234
|
schedule = described_class.parse( "min {28}" )
|
238
235
|
time = Time.iso8601( '2015-12-15T12:28:00-00:00' )
|
239
236
|
|
240
|
-
expect( schedule ).to_not include( time - 15
|
241
|
-
expect( schedule ).to_not include( time - 1
|
237
|
+
expect( schedule ).to_not include( time - 15 )
|
238
|
+
expect( schedule ).to_not include( time - 1 )
|
242
239
|
expect( schedule ).to include( time )
|
243
|
-
expect( schedule ).to include( time + 38
|
244
|
-
expect( schedule ).to include( time + 59
|
245
|
-
expect( schedule ).to_not include( time +
|
246
|
-
expect( schedule ).to_not include( time + 2
|
240
|
+
expect( schedule ).to include( time + 38 )
|
241
|
+
expect( schedule ).to include( time + 59 )
|
242
|
+
expect( schedule ).to_not include( time + 60 )
|
243
|
+
expect( schedule ).to_not include( time + 2 * 60 )
|
247
244
|
end
|
248
245
|
|
249
246
|
|
@@ -251,13 +248,13 @@ describe Schedulability::Schedule do
|
|
251
248
|
schedule = described_class.parse( "min {25-35}" )
|
252
249
|
time = Time.iso8601( '2015-12-15T12:25:00-00:00' )
|
253
250
|
|
254
|
-
expect( schedule ).to_not include( time -
|
255
|
-
expect( schedule ).to_not include( time - 1
|
251
|
+
expect( schedule ).to_not include( time - 60 )
|
252
|
+
expect( schedule ).to_not include( time - 1 )
|
256
253
|
expect( schedule ).to include( time )
|
257
|
-
expect( schedule ).to include( time +
|
258
|
-
expect( schedule ).to include( time + 9
|
259
|
-
expect( schedule ).to include( time + 9
|
260
|
-
expect( schedule ).to_not include( time + 10
|
254
|
+
expect( schedule ).to include( time + 60 )
|
255
|
+
expect( schedule ).to include( time + 9 * 60 )
|
256
|
+
expect( schedule ).to include( time + (9 * 60) + 59 )
|
257
|
+
expect( schedule ).to_not include( time + 10 * 60 )
|
261
258
|
end
|
262
259
|
|
263
260
|
|
@@ -265,18 +262,18 @@ describe Schedulability::Schedule do
|
|
265
262
|
schedule = described_class.parse( "min {50-15}" )
|
266
263
|
time = Time.iso8601( '2015-12-15T12:50:00-00:00' )
|
267
264
|
|
268
|
-
expect( schedule ).to_not include( time -
|
269
|
-
expect( schedule ).to_not include( time - 1
|
265
|
+
expect( schedule ).to_not include( time - 60 )
|
266
|
+
expect( schedule ).to_not include( time - 1 )
|
270
267
|
expect( schedule ).to include( time )
|
271
|
-
expect( schedule ).to include( time + 1
|
272
|
-
expect( schedule ).to include( time +
|
273
|
-
expect( schedule ).to include( time + 9
|
274
|
-
expect( schedule ).to include( time + 9
|
275
|
-
expect( schedule ).to include( time + 10
|
276
|
-
expect( schedule ).to include( time + 20
|
277
|
-
expect( schedule ).to include( time + 24
|
278
|
-
expect( schedule ).to include( time + 24
|
279
|
-
expect( schedule ).to_not include( time + 25
|
268
|
+
expect( schedule ).to include( time + 1 )
|
269
|
+
expect( schedule ).to include( time + 60 )
|
270
|
+
expect( schedule ).to include( time + 9 * 60 )
|
271
|
+
expect( schedule ).to include( time + 9 * 60 + 59 )
|
272
|
+
expect( schedule ).to include( time + 10 * 60 )
|
273
|
+
expect( schedule ).to include( time + 20 * 60 )
|
274
|
+
expect( schedule ).to include( time + 24 * 60 )
|
275
|
+
expect( schedule ).to include( time + 24 * 60 + 59 )
|
276
|
+
expect( schedule ).to_not include( time + 25 * 60 )
|
280
277
|
end
|
281
278
|
|
282
279
|
|
@@ -286,11 +283,11 @@ describe Schedulability::Schedule do
|
|
286
283
|
|
287
284
|
expect( schedule ).to_not include( time - 1 )
|
288
285
|
expect( schedule ).to include( time )
|
289
|
-
expect( schedule ).to include( time +
|
290
|
-
expect( schedule ).to include( time + 20
|
291
|
-
expect( schedule ).to include( time + (
|
292
|
-
expect( schedule ).to_not include( time +
|
293
|
-
expect( schedule ).to_not include( time + 3
|
286
|
+
expect( schedule ).to include( time + 60 )
|
287
|
+
expect( schedule ).to include( time + 20 * 60 )
|
288
|
+
expect( schedule ).to include( time + (3600 - 60) )
|
289
|
+
expect( schedule ).to_not include( time + 3600 )
|
290
|
+
expect( schedule ).to_not include( time + 3 * 3600 )
|
294
291
|
end
|
295
292
|
|
296
293
|
|
@@ -298,15 +295,15 @@ describe Schedulability::Schedule do
|
|
298
295
|
schedule = described_class.parse( "hr {9am-5pm}" )
|
299
296
|
time = Time.iso8601( '2015-12-15T09:00:00-00:00' )
|
300
297
|
|
301
|
-
expect( schedule ).to_not include( time - 12
|
302
|
-
expect( schedule ).to_not include( time - 10
|
303
|
-
expect( schedule ).to_not include( time - 1
|
298
|
+
expect( schedule ).to_not include( time - 12 * 3600 )
|
299
|
+
expect( schedule ).to_not include( time - 10 * 60 )
|
300
|
+
expect( schedule ).to_not include( time - 1 )
|
304
301
|
expect( schedule ).to include( time )
|
305
|
-
expect( schedule ).to include( time +
|
306
|
-
expect( schedule ).to include( time +
|
307
|
-
expect( schedule ).to include( time + 7
|
308
|
-
expect( schedule ).to include( time + (8
|
309
|
-
expect( schedule ).to_not include( time + 8
|
302
|
+
expect( schedule ).to include( time + 60 )
|
303
|
+
expect( schedule ).to include( time + 3600 )
|
304
|
+
expect( schedule ).to include( time + 7 * 3600 )
|
305
|
+
expect( schedule ).to include( time + (8 * 3600 - 1) )
|
306
|
+
expect( schedule ).to_not include( time + 8 * 3600 )
|
310
307
|
end
|
311
308
|
|
312
309
|
|
@@ -314,21 +311,21 @@ describe Schedulability::Schedule do
|
|
314
311
|
schedule = described_class.parse( "hr {5pm-9am}" )
|
315
312
|
time = Time.iso8601( '2015-12-15T17:00:00-00:00' )
|
316
313
|
|
317
|
-
expect( schedule ).to_not include( time -
|
318
|
-
expect( schedule ).to_not include( time - 1
|
314
|
+
expect( schedule ).to_not include( time - 3600 )
|
315
|
+
expect( schedule ).to_not include( time - 1 )
|
319
316
|
expect( schedule ).to include( time )
|
320
|
-
expect( schedule ).to include( time + 1
|
321
|
-
expect( schedule ).to include( time +
|
322
|
-
expect( schedule ).to include( time + 10
|
323
|
-
expect( schedule ).to include( time + 2
|
324
|
-
expect( schedule ).to include( time + (7
|
325
|
-
expect( schedule ).to include( time + 7
|
326
|
-
expect( schedule ).to include( time + 12
|
327
|
-
expect( schedule ).to include( time + (16
|
328
|
-
expect( schedule ).to include( time + 24
|
329
|
-
expect( schedule ).to_not include( time + (24
|
330
|
-
expect( schedule ).to_not include( time + 16
|
331
|
-
expect( schedule ).to_not include( time + 18
|
317
|
+
expect( schedule ).to include( time + 1 )
|
318
|
+
expect( schedule ).to include( time + 60 )
|
319
|
+
expect( schedule ).to include( time + 10 * 60 )
|
320
|
+
expect( schedule ).to include( time + 2 * 3600 )
|
321
|
+
expect( schedule ).to include( time + (7 * 3600 - 1) )
|
322
|
+
expect( schedule ).to include( time + 7 * 3600 )
|
323
|
+
expect( schedule ).to include( time + 12 * 3600 )
|
324
|
+
expect( schedule ).to include( time + (16 * 3600 - 1) )
|
325
|
+
expect( schedule ).to include( time + 24 * 3600 )
|
326
|
+
expect( schedule ).to_not include( time + (24 * 3600 - 1) )
|
327
|
+
expect( schedule ).to_not include( time + 16 * 3600 )
|
328
|
+
expect( schedule ).to_not include( time + 18 * 3600 )
|
332
329
|
end
|
333
330
|
|
334
331
|
|
@@ -338,11 +335,11 @@ describe Schedulability::Schedule do
|
|
338
335
|
|
339
336
|
expect( schedule ).to_not include( time - 1 )
|
340
337
|
expect( schedule ).to include( time )
|
341
|
-
expect( schedule ).to include( time +
|
342
|
-
expect( schedule ).to include( time + 20
|
343
|
-
expect( schedule ).to include( time + (
|
344
|
-
expect( schedule ).to_not include( time +
|
345
|
-
expect( schedule ).to_not include( time + 3
|
338
|
+
expect( schedule ).to include( time + 60 )
|
339
|
+
expect( schedule ).to include( time + 20 * 60 )
|
340
|
+
expect( schedule ).to include( time + (3600 - 60) )
|
341
|
+
expect( schedule ).to_not include( time + 3600 )
|
342
|
+
expect( schedule ).to_not include( time + 3 * 3600 )
|
346
343
|
end
|
347
344
|
|
348
345
|
|
@@ -353,11 +350,11 @@ describe Schedulability::Schedule do
|
|
353
350
|
|
354
351
|
expect( schedule ).to_not include( time - 1 )
|
355
352
|
expect( schedule ).to include( time )
|
356
|
-
expect( schedule ).to include( time +
|
357
|
-
expect( schedule ).to include( time + 20
|
358
|
-
expect( schedule ).to include( time + (
|
359
|
-
expect( schedule ).to_not include( time +
|
360
|
-
expect( schedule ).to_not include( time + 3
|
353
|
+
expect( schedule ).to include( time + 60 )
|
354
|
+
expect( schedule ).to include( time + 20 * 60 )
|
355
|
+
expect( schedule ).to include( time + (3600 - 60) )
|
356
|
+
expect( schedule ).to_not include( time + 3600 )
|
357
|
+
expect( schedule ).to_not include( time + 3 * 3600 )
|
361
358
|
end
|
362
359
|
|
363
360
|
|
@@ -367,11 +364,11 @@ describe Schedulability::Schedule do
|
|
367
364
|
|
368
365
|
expect( schedule ).to_not include( time - 1 )
|
369
366
|
expect( schedule ).to include( time )
|
370
|
-
expect( schedule ).to include( time +
|
371
|
-
expect( schedule ).to include( time + 20
|
372
|
-
expect( schedule ).to include( time + (
|
373
|
-
expect( schedule ).to_not include( time +
|
374
|
-
expect( schedule ).to_not include( time + 3
|
367
|
+
expect( schedule ).to include( time + 60 )
|
368
|
+
expect( schedule ).to include( time + 20 * 60 )
|
369
|
+
expect( schedule ).to include( time + (3600 - 60) )
|
370
|
+
expect( schedule ).to_not include( time + 3600 )
|
371
|
+
expect( schedule ).to_not include( time + 3 * 3600 )
|
375
372
|
end
|
376
373
|
|
377
374
|
|
@@ -381,11 +378,11 @@ describe Schedulability::Schedule do
|
|
381
378
|
|
382
379
|
expect( schedule ).to_not include( time - 1 )
|
383
380
|
expect( schedule ).to include( time )
|
384
|
-
expect( schedule ).to include( time +
|
385
|
-
expect( schedule ).to include( time + 20
|
386
|
-
expect( schedule ).to include( time + (
|
387
|
-
expect( schedule ).to_not include( time +
|
388
|
-
expect( schedule ).to_not include( time + 3
|
381
|
+
expect( schedule ).to include( time + 60 )
|
382
|
+
expect( schedule ).to include( time + 20 * 60 )
|
383
|
+
expect( schedule ).to include( time + (3600 - 60) )
|
384
|
+
expect( schedule ).to_not include( time + 3600 )
|
385
|
+
expect( schedule ).to_not include( time + 3 * 3600 )
|
389
386
|
end
|
390
387
|
|
391
388
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schedulability
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Granger
|
@@ -11,9 +11,9 @@ bindir: bin
|
|
11
11
|
cert_chain:
|
12
12
|
- |
|
13
13
|
-----BEGIN CERTIFICATE-----
|
14
|
-
|
14
|
+
MIIEbDCCAtSgAwIBAgIBATANBgkqhkiG9w0BAQUFADA+MQwwCgYDVQQDDANnZWQx
|
15
15
|
GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
|
16
|
-
|
16
|
+
HhcNMTcwOTI3MDAzMDQ0WhcNMTgwOTI3MDAzMDQ0WjA+MQwwCgYDVQQDDANnZWQx
|
17
17
|
GTAXBgoJkiaJk/IsZAEZFglGYWVyaWVNVUQxEzARBgoJkiaJk/IsZAEZFgNvcmcw
|
18
18
|
ggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC/JWGRHO+USzR97vXjkFgt
|
19
19
|
83qeNf2KHkcvrRTSnR64i6um/ziin0I0oX23H7VYrDJC9A/uoUa5nGRJS5Zw/+wW
|
@@ -26,17 +26,17 @@ cert_chain:
|
|
26
26
|
/D+K9JW9DDs3Yjgv9k4h7YMhW5gftosd+NkNC/+Y2CkCAwEAAaN1MHMwCQYDVR0T
|
27
27
|
BAIwADALBgNVHQ8EBAMCBLAwHQYDVR0OBBYEFHKN/nkRusdqCJEuq3lgB3fJvyTg
|
28
28
|
MBwGA1UdEQQVMBOBEWdlZEBGYWVyaWVNVUQub3JnMBwGA1UdEgQVMBOBEWdlZEBG
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
YWVyaWVNVUQub3JnMA0GCSqGSIb3DQEBBQUAA4IBgQB/qyi5pCjK8ceoKalfVAjS
|
30
|
+
vG64FEnLnD1bm39T5UaFIRmo+abZtfpg2QhwKvPbPjOicau2+m+MDQ2Cc3tgyaC3
|
31
|
+
dZxcP6w8APFg4AId09uWAZKf0xajvBMS2aOz8Bbmag6fwqRRkTMqsNYnmqcF7aRT
|
32
|
+
DuEzbEMfaOUYjU9RuB48vr4q8yRft0ww+3jq5iwNkrX1buL2pwBbyvgms6D/BV41
|
33
|
+
MaTVMjsHqJUwU2xVfhGtxGAWAer5S1HGYHkbio6mGVtiie0uWjmnzi7ppIlMr48a
|
34
|
+
7BNTsoZ+/JRk3iQWmmNsyFT7xfqBKye7cH11BX8V8P4MeGB5YWlMI+Myj5DZY3fQ
|
35
|
+
st2AGD4rb1l0ia7PfubcBThSIdz61eCb8gRi/RiZZwb3/7+eyEncLJzt2Ob9fGSF
|
36
|
+
X0qdrKi+2aZZ0NGuFj9AItBsVmAvkBGIpX4TEKQp5haEbPpmaqO5nIIhV26PXmyT
|
37
|
+
OMKv6pWsoS81vw5KAGBmfX8nht/Py90DQrbRvakATGI=
|
38
38
|
-----END CERTIFICATE-----
|
39
|
-
date:
|
39
|
+
date: 2018-09-12 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: loggability
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0.
|
75
|
+
version: '0.9'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0.
|
82
|
+
version: '0.9'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: hoe-highline
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,33 +95,33 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.2'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: timecop
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '0.8'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '0.8'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rdoc
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '4.2'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '4.2'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: simplecov
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,14 +142,14 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '3.
|
145
|
+
version: '3.16'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '3.
|
152
|
+
version: '3.16'
|
153
153
|
description: |-
|
154
154
|
Schedulability is a library for describing scheduled time. You can specify one
|
155
155
|
or more periods of time using a simple syntax, then combine them to describe
|
@@ -173,11 +173,9 @@ files:
|
|
173
173
|
- Rakefile
|
174
174
|
- lib/schedulability.rb
|
175
175
|
- lib/schedulability/exceptions.rb
|
176
|
-
- lib/schedulability/mixins.rb
|
177
176
|
- lib/schedulability/parser.rb
|
178
177
|
- lib/schedulability/schedule.rb
|
179
178
|
- spec/helpers.rb
|
180
|
-
- spec/schedulability/mixins_spec.rb
|
181
179
|
- spec/schedulability/parser_spec.rb
|
182
180
|
- spec/schedulability/schedule_spec.rb
|
183
181
|
- spec/schedulability_spec.rb
|
@@ -203,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
201
|
version: '0'
|
204
202
|
requirements: []
|
205
203
|
rubyforge_project:
|
206
|
-
rubygems_version: 2.
|
204
|
+
rubygems_version: 2.7.6
|
207
205
|
signing_key:
|
208
206
|
specification_version: 4
|
209
207
|
summary: Schedulability is a library for describing scheduled time
|
metadata.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
�`�>zuc���S�LA�)B���2B0�)�u�,��}�=Q&�A��'h�k5F8���}�@���I�`�Hu�[�p����J.��Z�]D%���XWԗicx)��fE�b
|
2
|
+
X���c�����Ձc�E�j��U%Dx���?!)��<"m�
|
@@ -1,201 +0,0 @@
|
|
1
|
-
# -*- ruby -*-
|
2
|
-
#encoding: utf-8
|
3
|
-
|
4
|
-
require 'schedulability' unless defined?( Schedulability )
|
5
|
-
|
6
|
-
module Schedulability
|
7
|
-
|
8
|
-
# Functions for time calculations
|
9
|
-
module TimeFunctions
|
10
|
-
|
11
|
-
###############
|
12
|
-
module_function
|
13
|
-
###############
|
14
|
-
|
15
|
-
### Calculate the (approximate) number of seconds that are in +count+ of the
|
16
|
-
### given +unit+ of time.
|
17
|
-
###
|
18
|
-
def calculate_seconds( count, unit )
|
19
|
-
return case unit
|
20
|
-
when :seconds, :second
|
21
|
-
count
|
22
|
-
when :minutes, :minute
|
23
|
-
count * 60
|
24
|
-
when :hours, :hour
|
25
|
-
count * 3600
|
26
|
-
when :days, :day
|
27
|
-
count * 86400
|
28
|
-
when :weeks, :week
|
29
|
-
count * 604800
|
30
|
-
when :fortnights, :fortnight
|
31
|
-
count * 1209600
|
32
|
-
when :months, :month
|
33
|
-
count * 2592000
|
34
|
-
when :years, :year
|
35
|
-
count * 31557600
|
36
|
-
else
|
37
|
-
raise ArgumentError, "don't know how to calculate seconds in a %p" % [ unit ]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end # module TimeFunctions
|
41
|
-
|
42
|
-
|
43
|
-
# Refinements to Numeric to add time-related convenience methods
|
44
|
-
module TimeRefinements
|
45
|
-
refine Numeric do
|
46
|
-
|
47
|
-
### Number of seconds (returns receiver unmodified)
|
48
|
-
def seconds
|
49
|
-
return self
|
50
|
-
end
|
51
|
-
alias_method :second, :seconds
|
52
|
-
|
53
|
-
### Returns number of seconds in <receiver> minutes
|
54
|
-
def minutes
|
55
|
-
return TimeFunctions.calculate_seconds( self, :minutes )
|
56
|
-
end
|
57
|
-
alias_method :minute, :minutes
|
58
|
-
|
59
|
-
### Returns the number of seconds in <receiver> hours
|
60
|
-
def hours
|
61
|
-
return TimeFunctions.calculate_seconds( self, :hours )
|
62
|
-
end
|
63
|
-
alias_method :hour, :hours
|
64
|
-
|
65
|
-
### Returns the number of seconds in <receiver> days
|
66
|
-
def days
|
67
|
-
return TimeFunctions.calculate_seconds( self, :day )
|
68
|
-
end
|
69
|
-
alias_method :day, :days
|
70
|
-
|
71
|
-
### Return the number of seconds in <receiver> weeks
|
72
|
-
def weeks
|
73
|
-
return TimeFunctions.calculate_seconds( self, :weeks )
|
74
|
-
end
|
75
|
-
alias_method :week, :weeks
|
76
|
-
|
77
|
-
### Returns the number of seconds in <receiver> fortnights
|
78
|
-
def fortnights
|
79
|
-
return TimeFunctions.calculate_seconds( self, :fortnights )
|
80
|
-
end
|
81
|
-
alias_method :fortnight, :fortnights
|
82
|
-
|
83
|
-
### Returns the number of seconds in <receiver> months (approximate)
|
84
|
-
def months
|
85
|
-
return TimeFunctions.calculate_seconds( self, :months )
|
86
|
-
end
|
87
|
-
alias_method :month, :months
|
88
|
-
|
89
|
-
### Returns the number of seconds in <receiver> years (approximate)
|
90
|
-
def years
|
91
|
-
return TimeFunctions.calculate_seconds( self, :years )
|
92
|
-
end
|
93
|
-
alias_method :year, :years
|
94
|
-
|
95
|
-
|
96
|
-
### Returns the Time <receiver> number of seconds before the
|
97
|
-
### specified +time+. E.g., 2.hours.before( header.expiration )
|
98
|
-
def before( time )
|
99
|
-
return time - self
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
### Returns the Time <receiver> number of seconds ago. (e.g.,
|
104
|
-
### expiration > 2.hours.ago )
|
105
|
-
def ago
|
106
|
-
return self.before( ::Time.now )
|
107
|
-
end
|
108
|
-
|
109
|
-
|
110
|
-
### Returns the Time <receiver> number of seconds after the given +time+.
|
111
|
-
### E.g., 10.minutes.after( header.expiration )
|
112
|
-
def after( time )
|
113
|
-
return time + self
|
114
|
-
end
|
115
|
-
|
116
|
-
|
117
|
-
### Return a new Time <receiver> number of seconds from now.
|
118
|
-
def from_now
|
119
|
-
return self.after( ::Time.now )
|
120
|
-
end
|
121
|
-
|
122
|
-
end # refine Numeric
|
123
|
-
|
124
|
-
|
125
|
-
refine Time do
|
126
|
-
|
127
|
-
# Approximate Time Constants (in seconds)
|
128
|
-
MINUTES = 60
|
129
|
-
HOURS = 60 * MINUTES
|
130
|
-
DAYS = 24 * HOURS
|
131
|
-
WEEKS = 7 * DAYS
|
132
|
-
MONTHS = 30 * DAYS
|
133
|
-
YEARS = 365.25 * DAYS
|
134
|
-
|
135
|
-
|
136
|
-
### Returns +true+ if the receiver is a Time in the future.
|
137
|
-
def future?
|
138
|
-
return self > Time.now
|
139
|
-
end
|
140
|
-
|
141
|
-
|
142
|
-
### Returns +true+ if the receiver is a Time in the past.
|
143
|
-
def past?
|
144
|
-
return self < Time.now
|
145
|
-
end
|
146
|
-
|
147
|
-
|
148
|
-
### Return a description of the receiving Time object in relation to the current
|
149
|
-
### time.
|
150
|
-
###
|
151
|
-
### Example:
|
152
|
-
###
|
153
|
-
### "Saved %s ago." % object.updated_at.as_delta
|
154
|
-
def as_delta
|
155
|
-
now = Time.now
|
156
|
-
if now > self
|
157
|
-
seconds = now - self
|
158
|
-
return "%s ago" % [ timeperiod(seconds) ]
|
159
|
-
else
|
160
|
-
seconds = self - now
|
161
|
-
return "%s from now" % [ timeperiod(seconds) ]
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
|
166
|
-
### Return a description of +seconds+ as the nearest whole unit of time.
|
167
|
-
def timeperiod( seconds )
|
168
|
-
return case
|
169
|
-
when seconds < MINUTES - 5
|
170
|
-
'less than a minute'
|
171
|
-
when seconds < 50 * MINUTES
|
172
|
-
if seconds <= 89
|
173
|
-
"a minute"
|
174
|
-
else
|
175
|
-
"%d minutes" % [ (seconds.to_f / MINUTES).ceil ]
|
176
|
-
end
|
177
|
-
when seconds < 90 * MINUTES
|
178
|
-
'about an hour'
|
179
|
-
when seconds < 18 * HOURS
|
180
|
-
"%d hours" % [ (seconds.to_f / HOURS).ceil ]
|
181
|
-
when seconds < 30 * HOURS
|
182
|
-
'about a day'
|
183
|
-
when seconds < WEEKS
|
184
|
-
"%d days" % [ (seconds.to_f / DAYS).ceil ]
|
185
|
-
when seconds < 2 * WEEKS
|
186
|
-
'about a week'
|
187
|
-
when seconds < 3 * MONTHS
|
188
|
-
"%d weeks" % [ (seconds.to_f / WEEKS).round ]
|
189
|
-
when seconds < 18 * MONTHS
|
190
|
-
"%d months" % [ (seconds.to_f / MONTHS).ceil ]
|
191
|
-
else
|
192
|
-
"%d years" % [ (seconds.to_f / YEARS).ceil ]
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
end # refine Time
|
197
|
-
|
198
|
-
end # module TimeRefinements
|
199
|
-
|
200
|
-
end # module Schedulability
|
201
|
-
|
@@ -1,164 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rspec -cfd
|
2
|
-
|
3
|
-
require_relative '../helpers'
|
4
|
-
|
5
|
-
require 'schedulability/mixins'
|
6
|
-
|
7
|
-
|
8
|
-
describe Schedulability, 'mixins' do
|
9
|
-
|
10
|
-
|
11
|
-
describe Schedulability::TimeRefinements do
|
12
|
-
|
13
|
-
using( described_class )
|
14
|
-
|
15
|
-
|
16
|
-
describe "used to extend Numeric objects" do
|
17
|
-
|
18
|
-
SECONDS_IN_A_MINUTE = 60
|
19
|
-
SECONDS_IN_AN_HOUR = SECONDS_IN_A_MINUTE * 60
|
20
|
-
SECONDS_IN_A_DAY = SECONDS_IN_AN_HOUR * 24
|
21
|
-
SECONDS_IN_A_WEEK = SECONDS_IN_A_DAY * 7
|
22
|
-
SECONDS_IN_A_FORTNIGHT = SECONDS_IN_A_WEEK * 2
|
23
|
-
SECONDS_IN_A_MONTH = SECONDS_IN_A_DAY * 30
|
24
|
-
SECONDS_IN_A_YEAR = Integer( SECONDS_IN_A_DAY * 365.25 )
|
25
|
-
|
26
|
-
|
27
|
-
it "can calculate the number of seconds for various units of time" do
|
28
|
-
expect( 1.second ).to eq( 1 )
|
29
|
-
expect( 14.seconds ).to eq( 14 )
|
30
|
-
|
31
|
-
expect( 1.minute ).to eq( SECONDS_IN_A_MINUTE )
|
32
|
-
expect( 18.minutes ).to eq( SECONDS_IN_A_MINUTE * 18 )
|
33
|
-
|
34
|
-
expect( 1.hour ).to eq( SECONDS_IN_AN_HOUR )
|
35
|
-
expect( 723.hours ).to eq( SECONDS_IN_AN_HOUR * 723 )
|
36
|
-
|
37
|
-
expect( 1.day ).to eq( SECONDS_IN_A_DAY )
|
38
|
-
expect( 3.days ).to eq( SECONDS_IN_A_DAY * 3 )
|
39
|
-
|
40
|
-
expect( 1.week ).to eq( SECONDS_IN_A_WEEK )
|
41
|
-
expect( 28.weeks ).to eq( SECONDS_IN_A_WEEK * 28 )
|
42
|
-
|
43
|
-
expect( 1.fortnight ).to eq( SECONDS_IN_A_FORTNIGHT )
|
44
|
-
expect( 31.fortnights ).to eq( SECONDS_IN_A_FORTNIGHT * 31 )
|
45
|
-
|
46
|
-
expect( 1.month ).to eq( SECONDS_IN_A_MONTH )
|
47
|
-
expect( 67.months ).to eq( SECONDS_IN_A_MONTH * 67 )
|
48
|
-
|
49
|
-
expect( 1.year ).to eq( SECONDS_IN_A_YEAR )
|
50
|
-
expect( 13.years ).to eq( SECONDS_IN_A_YEAR * 13 )
|
51
|
-
end
|
52
|
-
|
53
|
-
|
54
|
-
it "can calculate various time offsets" do
|
55
|
-
starttime = Time.now
|
56
|
-
|
57
|
-
expect( 1.second.after( starttime ) ).to eq( starttime + 1 )
|
58
|
-
expect( 18.seconds.from_now ).to be_within( 10.seconds ).of( starttime + 18 )
|
59
|
-
|
60
|
-
expect( 1.second.before( starttime ) ).to eq( starttime - 1 )
|
61
|
-
expect( 3.hours.ago ).to be_within( 10.seconds ).of( starttime - 10800 )
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
context "used to extend Time objects" do
|
68
|
-
|
69
|
-
it "makes them aware of whether they're in the future or not" do
|
70
|
-
Timecop.freeze do
|
71
|
-
time = Time.now
|
72
|
-
expect( time.future? ).to be_falsey
|
73
|
-
|
74
|
-
future_time = time + 1
|
75
|
-
expect( future_time.future? ).to be_truthy
|
76
|
-
|
77
|
-
past_time = time - 1
|
78
|
-
expect( past_time.future? ).to be_falsey
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
|
-
it "makes them aware of whether they're in the past or not" do
|
84
|
-
Timecop.freeze do
|
85
|
-
time = Time.now
|
86
|
-
expect( time.past? ).to be_falsey
|
87
|
-
|
88
|
-
future_time = time + 1
|
89
|
-
expect( future_time.past? ).to be_falsey
|
90
|
-
|
91
|
-
past_time = time - 1
|
92
|
-
expect( past_time.past? ).to be_truthy
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
|
97
|
-
it "adds the ability to express themselves as an offset in English" do
|
98
|
-
Timecop.freeze do
|
99
|
-
expect( 1.second.ago.as_delta ).to eq( 'less than a minute ago' )
|
100
|
-
expect( 1.second.from_now.as_delta ).to eq( 'less than a minute from now' )
|
101
|
-
|
102
|
-
expect( 1.minute.ago.as_delta ).to eq( 'a minute ago' )
|
103
|
-
expect( 1.minute.from_now.as_delta ).to eq( 'a minute from now' )
|
104
|
-
expect( 68.seconds.ago.as_delta ).to eq( 'a minute ago' )
|
105
|
-
expect( 68.seconds.from_now.as_delta ).to eq( 'a minute from now' )
|
106
|
-
expect( 2.minutes.ago.as_delta ).to eq( '2 minutes ago' )
|
107
|
-
expect( 2.minutes.from_now.as_delta ).to eq( '2 minutes from now' )
|
108
|
-
expect( 38.minutes.ago.as_delta ).to eq( '38 minutes ago' )
|
109
|
-
expect( 38.minutes.from_now.as_delta ).to eq( '38 minutes from now' )
|
110
|
-
|
111
|
-
expect( 1.hour.ago.as_delta ).to eq( 'about an hour ago' )
|
112
|
-
expect( 1.hour.from_now.as_delta ).to eq( 'about an hour from now' )
|
113
|
-
expect( 75.minutes.ago.as_delta ).to eq( 'about an hour ago' )
|
114
|
-
expect( 75.minutes.from_now.as_delta ).to eq( 'about an hour from now' )
|
115
|
-
|
116
|
-
expect( 2.hours.ago.as_delta ).to eq( '2 hours ago' )
|
117
|
-
expect( 2.hours.from_now.as_delta ).to eq( '2 hours from now' )
|
118
|
-
expect( 14.hours.ago.as_delta ).to eq( '14 hours ago' )
|
119
|
-
expect( 14.hours.from_now.as_delta ).to eq( '14 hours from now' )
|
120
|
-
|
121
|
-
expect( 22.hours.ago.as_delta ).to eq( 'about a day ago' )
|
122
|
-
expect( 22.hours.from_now.as_delta ).to eq( 'about a day from now' )
|
123
|
-
expect( 28.hours.ago.as_delta ).to eq( 'about a day ago' )
|
124
|
-
expect( 28.hours.from_now.as_delta ).to eq( 'about a day from now' )
|
125
|
-
|
126
|
-
expect( 36.hours.ago.as_delta ).to eq( '2 days ago' )
|
127
|
-
expect( 36.hours.from_now.as_delta ).to eq( '2 days from now' )
|
128
|
-
expect( 4.days.ago.as_delta ).to eq( '4 days ago' )
|
129
|
-
expect( 4.days.from_now.as_delta ).to eq( '4 days from now' )
|
130
|
-
|
131
|
-
expect( 1.week.ago.as_delta ).to eq( 'about a week ago' )
|
132
|
-
expect( 1.week.from_now.as_delta ).to eq( 'about a week from now' )
|
133
|
-
expect( 8.days.ago.as_delta ).to eq( 'about a week ago' )
|
134
|
-
expect( 8.days.from_now.as_delta ).to eq( 'about a week from now' )
|
135
|
-
|
136
|
-
expect( 15.days.ago.as_delta ).to eq( '2 weeks ago' )
|
137
|
-
expect( 15.days.from_now.as_delta ).to eq( '2 weeks from now' )
|
138
|
-
expect( 3.weeks.ago.as_delta ).to eq( '3 weeks ago' )
|
139
|
-
expect( 3.weeks.from_now.as_delta ).to eq( '3 weeks from now' )
|
140
|
-
|
141
|
-
expect( 1.month.ago.as_delta ).to eq( '4 weeks ago' )
|
142
|
-
expect( 1.month.from_now.as_delta ).to eq( '4 weeks from now' )
|
143
|
-
expect( 36.days.ago.as_delta ).to eq( '5 weeks ago' )
|
144
|
-
expect( 36.days.from_now.as_delta ).to eq( '5 weeks from now' )
|
145
|
-
|
146
|
-
expect( 6.months.ago.as_delta ).to eq( '6 months ago' )
|
147
|
-
expect( 6.months.from_now.as_delta ).to eq( '6 months from now' )
|
148
|
-
expect( 14.months.ago.as_delta ).to eq( '14 months ago' )
|
149
|
-
expect( 14.months.from_now.as_delta ).to eq( '14 months from now' )
|
150
|
-
|
151
|
-
expect( 6.year.ago.as_delta ).to eq( '6 years ago' )
|
152
|
-
expect( 6.year.from_now.as_delta ).to eq( '6 years from now' )
|
153
|
-
expect( 14.years.ago.as_delta ).to eq( '14 years ago' )
|
154
|
-
expect( 14.years.from_now.as_delta ).to eq( '14 years from now' )
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
end
|
159
|
-
|
160
|
-
end
|
161
|
-
|
162
|
-
|
163
|
-
end
|
164
|
-
|