fugit 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of fugit might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -0
- data/lib/fugit.rb +1 -1
- data/lib/fugit/cron.rb +69 -0
- 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: f27107c7603ef6d23deb7ce3a37f377f91efc738
|
4
|
+
data.tar.gz: 01322c2865d102807fe4e263c83d6c6ce56853d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acbd5be7fe73de2b68cb518f6626f93d1d7c06f474cb89c2ae487013854deeaebf5029c97ee57d97832f0f2f81a819eeed65a5cf9929dc81bc3c7a7baa0832fc
|
7
|
+
data.tar.gz: 7cfd640731cf49b1ac378d21dc310e852c1bdc995b4ec90228c55db7685041195b3df5caf69e88cf446eb8112fcd4839572dcb542f3b32a424d4469cf74927e1
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
# fugit CHANGELOG.md
|
3
3
|
|
4
4
|
|
5
|
+
## fugit 1.1.5 released 2018-07-30
|
6
|
+
|
7
|
+
* Add Fugit::Cron#rough_frequency (for https://github.com/jmettraux/rufus-scheduler/pull/276)
|
8
|
+
|
9
|
+
|
5
10
|
## fugit 1.1.4 released 2018-07-20
|
6
11
|
|
7
12
|
* Add duration support for Fugit::Nat (@cristianbica gh-7)
|
data/README.md
CHANGED
@@ -63,6 +63,7 @@ p c.previous_time # => 2017-01-01 00:00:00 +0900
|
|
63
63
|
|
64
64
|
p c.brute_frequency # => [ 604800, 604800, 53 ]
|
65
65
|
# [ delta min, delta max, occurrence count ]
|
66
|
+
p c.rough_frequency # => 7 * 24 * 3600 (7d rough frequency)
|
66
67
|
|
67
68
|
p c.match?(Time.parse('2017-08-06')) # => true
|
68
69
|
p c.match?(Time.parse('2017-08-07')) # => false
|
data/lib/fugit.rb
CHANGED
data/lib/fugit/cron.rb
CHANGED
@@ -250,6 +250,40 @@ module Fugit
|
|
250
250
|
end
|
251
251
|
end
|
252
252
|
|
253
|
+
SLOTS = [
|
254
|
+
[ :seconds, 1, 60 ],
|
255
|
+
[ :minutes, 60, 60 ],
|
256
|
+
[ :hours, 3600, 24 ],
|
257
|
+
[ :days, 24 * 3600, 365 ] ]
|
258
|
+
|
259
|
+
def rough_frequency
|
260
|
+
|
261
|
+
slots = SLOTS
|
262
|
+
.collect { |k, v0, v1|
|
263
|
+
a = (k == :days) ? rough_days : instance_variable_get("@#{k}")
|
264
|
+
[ k, v0, v1, a ] }
|
265
|
+
|
266
|
+
slots.each do |k, v0, _, a|
|
267
|
+
next if a == [ 0 ]
|
268
|
+
break if a != nil
|
269
|
+
return v0 if a == nil
|
270
|
+
end
|
271
|
+
|
272
|
+
slots.each do |k, v0, v1, a|
|
273
|
+
next unless a && a.length > 1
|
274
|
+
return (a + [ a.first + v1 ])
|
275
|
+
.each_cons(2)
|
276
|
+
.collect { |a0, a1| a1 - a0 }
|
277
|
+
.min * v0
|
278
|
+
end
|
279
|
+
|
280
|
+
slots.reverse.each do |k, v0, v1, a|
|
281
|
+
return v0 * v1 if a && a.length == 1
|
282
|
+
end
|
283
|
+
|
284
|
+
1 # second
|
285
|
+
end
|
286
|
+
|
253
287
|
class Frequency
|
254
288
|
|
255
289
|
attr_reader :span, :delta_min, :delta_max, :occurrences
|
@@ -283,6 +317,16 @@ module Fugit
|
|
283
317
|
[ @seconds, @minutes, @hours, @monthdays, @months, @weekdays ]
|
284
318
|
end
|
285
319
|
|
320
|
+
def to_h
|
321
|
+
|
322
|
+
{ seconds: @seconds,
|
323
|
+
minutes: @minutes,
|
324
|
+
hours: @hours,
|
325
|
+
monthdays: @monthdays,
|
326
|
+
months: @months,
|
327
|
+
weekdays: @weekdays }
|
328
|
+
end
|
329
|
+
|
286
330
|
def ==(o)
|
287
331
|
|
288
332
|
o.is_a?(::Fugit::Cron) && o.to_a == to_a
|
@@ -296,6 +340,31 @@ module Fugit
|
|
296
340
|
|
297
341
|
protected
|
298
342
|
|
343
|
+
def rough_days
|
344
|
+
|
345
|
+
return nil if @weekdays == nil && @monthdays == nil
|
346
|
+
|
347
|
+
months = (@months || (1..12).to_a)
|
348
|
+
|
349
|
+
monthdays = months
|
350
|
+
.product(@monthdays || [])
|
351
|
+
.collect { |m, d|
|
352
|
+
d = 31 + d if d < 0
|
353
|
+
(m - 1) * 30 + d } # rough
|
354
|
+
|
355
|
+
weekdays = (@weekdays || [])
|
356
|
+
.collect { |d, w|
|
357
|
+
w ?
|
358
|
+
d + (w - 1) * 7 :
|
359
|
+
(0..3).collect { |ww| d + ww * 7 } }
|
360
|
+
.flatten
|
361
|
+
weekdays = months
|
362
|
+
.product(weekdays)
|
363
|
+
.collect { |m, d| (m - 1) * 30 + d } # rough
|
364
|
+
|
365
|
+
(monthdays + weekdays).sort
|
366
|
+
end
|
367
|
+
|
299
368
|
FREQUENCY_CACHE = {}
|
300
369
|
|
301
370
|
def init(original, h)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fugit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: raabro
|