fugit 0.9.4 → 0.9.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 +6 -0
- data/lib/fugit.rb +2 -2
- data/lib/fugit/cron.rb +24 -22
- data/lib/fugit/duration.rb +5 -3
- data/lib/fugit/nat.rb +9 -0
- data/lib/fugit/{core.rb → parse.rb} +25 -22
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 614db4a7a2630eee78f008aa1a446ec9b59acfd1
|
4
|
+
data.tar.gz: 5325bc91f0aa055571b1c07f6e8e87357929898f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5622b68c6eeec8702bb0a1cba25144c67905a3e92d839e22906192b9acecef71258810043b5ba30d3c8f76757f8adc9a9b60c2b233186bf3d7018e14c59fb00b
|
7
|
+
data.tar.gz: 7a0c9ff30fd795138f664f170d4998aeb981591349a34fe246a0c6b86ec02f33c830a8d9792b6582327723268514b3db1eda50c7d7a73581845f96ce37321e27
|
data/CHANGELOG.md
CHANGED
data/lib/fugit.rb
CHANGED
@@ -25,7 +25,7 @@
|
|
25
25
|
|
26
26
|
module Fugit
|
27
27
|
|
28
|
-
VERSION = '0.9.
|
28
|
+
VERSION = '0.9.5'
|
29
29
|
end
|
30
30
|
|
31
31
|
require 'time'
|
@@ -33,9 +33,9 @@ require 'stringio'
|
|
33
33
|
|
34
34
|
require 'raabro'
|
35
35
|
|
36
|
-
require 'fugit/core'
|
37
36
|
require 'fugit/misc'
|
38
37
|
require 'fugit/cron'
|
39
38
|
require 'fugit/duration'
|
40
39
|
require 'fugit/nat'
|
40
|
+
require 'fugit/parse'
|
41
41
|
|
data/lib/fugit/cron.rb
CHANGED
@@ -67,6 +67,8 @@ module Fugit
|
|
67
67
|
original = s
|
68
68
|
s = SPECIALS[s] || s
|
69
69
|
|
70
|
+
return nil unless s.is_a?(String)
|
71
|
+
|
70
72
|
#p s; Raabro.pp(Parser.parse(s, debug: 3))
|
71
73
|
h = Parser.parse(s)
|
72
74
|
|
@@ -80,10 +82,10 @@ module Fugit
|
|
80
82
|
parse(s) || fail(ArgumentError.new("not a cron string #{s.inspect}"))
|
81
83
|
end
|
82
84
|
|
83
|
-
class
|
85
|
+
class TimeCursor # TODO at some point, use ZoTime
|
84
86
|
|
85
87
|
def initialize(t)
|
86
|
-
@t = t.is_a?(
|
88
|
+
@t = t.is_a?(TimeCursor) ? t.time : t
|
87
89
|
end
|
88
90
|
|
89
91
|
def time; @t; end
|
@@ -173,7 +175,7 @@ module Fugit
|
|
173
175
|
|
174
176
|
return true if @monthdays.nil?
|
175
177
|
|
176
|
-
last = (
|
178
|
+
last = (TimeCursor.new(nt).inc_month.time - 24 * 3600).day + 1
|
177
179
|
|
178
180
|
@monthdays
|
179
181
|
.collect { |d| d < 1 ? last + d : d }
|
@@ -194,7 +196,7 @@ module Fugit
|
|
194
196
|
def match?(t)
|
195
197
|
|
196
198
|
t = Fugit.do_parse_at(t)
|
197
|
-
t =
|
199
|
+
t = TimeCursor.new(t)
|
198
200
|
|
199
201
|
month_match?(t) && day_match?(t) &&
|
200
202
|
hour_match?(t) && min_match?(t) && sec_match?(t)
|
@@ -202,38 +204,38 @@ module Fugit
|
|
202
204
|
|
203
205
|
def next_time(from=Time.now)
|
204
206
|
|
205
|
-
|
207
|
+
t = TimeCursor.new(from)
|
206
208
|
|
207
209
|
loop do
|
208
|
-
#p [ :l, Fugit.time_to_s(
|
209
|
-
(from.to_i ==
|
210
|
-
month_match?(
|
211
|
-
day_match?(
|
212
|
-
hour_match?(
|
213
|
-
min_match?(
|
214
|
-
sec_match?(
|
210
|
+
#p [ :l, Fugit.time_to_s(t.time) ]
|
211
|
+
(from.to_i == t.to_i) && (t.inc(1); next)
|
212
|
+
month_match?(t) || (t.inc_month; next)
|
213
|
+
day_match?(t) || (t.inc_day; next)
|
214
|
+
hour_match?(t) || (t.inc_hour; next)
|
215
|
+
min_match?(t) || (t.inc_min; next)
|
216
|
+
sec_match?(t) || (t.inc_sec(@seconds); next)
|
215
217
|
break
|
216
218
|
end
|
217
219
|
|
218
|
-
|
220
|
+
t.time
|
219
221
|
end
|
220
222
|
|
221
223
|
def previous_time(from=Time.now)
|
222
224
|
|
223
|
-
|
225
|
+
t = TimeCursor.new(from)
|
224
226
|
|
225
227
|
loop do
|
226
|
-
#p [ :l, Fugit.time_to_s(
|
227
|
-
(from.to_i ==
|
228
|
-
month_match?(
|
229
|
-
day_match?(
|
230
|
-
hour_match?(
|
231
|
-
min_match?(
|
232
|
-
sec_match?(
|
228
|
+
#p [ :l, Fugit.time_to_s(t.time) ]
|
229
|
+
(from.to_i == t.to_i) && (t.inc(-1); next)
|
230
|
+
month_match?(t) || (t.dec_month; next)
|
231
|
+
day_match?(t) || (t.dec_day; next)
|
232
|
+
hour_match?(t) || (t.dec_hour; next)
|
233
|
+
min_match?(t) || (t.dec_min; next)
|
234
|
+
sec_match?(t) || (t.dec_sec(@seconds); next)
|
233
235
|
break
|
234
236
|
end
|
235
237
|
|
236
|
-
|
238
|
+
t.time
|
237
239
|
end
|
238
240
|
|
239
241
|
# Mostly used as a #next_time sanity check.
|
data/lib/fugit/duration.rb
CHANGED
@@ -40,9 +40,11 @@ module Fugit
|
|
40
40
|
|
41
41
|
original = s
|
42
42
|
|
43
|
-
s = s
|
44
|
-
|
45
|
-
|
43
|
+
s = s.to_s if s.is_a?(Numeric)
|
44
|
+
|
45
|
+
return nil unless s.is_a?(String)
|
46
|
+
|
47
|
+
s = s.strip
|
46
48
|
s = s + 's' if s.match(/\A-?(\d*\.)?\d+\z/)
|
47
49
|
#p [ original, s ]; Raabro.pp(Parser.parse(s, debug: 3))
|
48
50
|
|
data/lib/fugit/nat.rb
CHANGED
@@ -32,6 +32,10 @@ module Fugit
|
|
32
32
|
|
33
33
|
def self.parse(s)
|
34
34
|
|
35
|
+
return s if s.is_a?(Fugit::Cron) || s.is_a?(Fugit::Duration)
|
36
|
+
|
37
|
+
return nil unless s.is_a?(String)
|
38
|
+
|
35
39
|
#p s; Raabro.pp(Parser.parse(s, debug: 3))
|
36
40
|
a = Parser.parse(s)
|
37
41
|
|
@@ -45,6 +49,11 @@ module Fugit
|
|
45
49
|
end
|
46
50
|
end
|
47
51
|
|
52
|
+
def self.do_parse(s)
|
53
|
+
|
54
|
+
parse(s) || fail(ArgumentError.new("could not parse a nat #{s.inspect}"))
|
55
|
+
end
|
56
|
+
|
48
57
|
def self.parse_cron(a)
|
49
58
|
|
50
59
|
h = { min: nil, hou: [], dom: [ nil ], mon: [ nil ], dow: [ nil ] }
|
@@ -36,38 +36,41 @@ module Fugit
|
|
36
36
|
Time.parse(s)
|
37
37
|
end
|
38
38
|
|
39
|
-
def self.parse_cron(s)
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.do_parse_cron(s)
|
45
|
-
|
46
|
-
::Fugit::Cron.do_parse(s)
|
47
|
-
end
|
39
|
+
def self.parse_cron(s); ::Fugit::Cron.parse(s); end
|
40
|
+
def self.parse_duration(s); ::Fugit::Duration.parse(s); end
|
41
|
+
def self.parse_in(s); parse_duration(s); end
|
42
|
+
def self.parse_nat(s); ::Fugit::Nat.parse(s); end
|
48
43
|
|
49
|
-
def self.
|
44
|
+
def self.do_parse_cron(s); ::Fugit::Cron.do_parse(s); end
|
45
|
+
def self.do_parse_duration(s); ::Fugit::Duration.do_parse(s); end
|
46
|
+
def self.do_parse_in(s); do_parse_duration(s); end
|
47
|
+
def self.do_parse_nat(s); ::Fugit::Nat.do_parse(s); end
|
50
48
|
|
51
|
-
|
52
|
-
end
|
49
|
+
def self.parse(s, opts={})
|
53
50
|
|
54
|
-
|
51
|
+
opts[:at] = opts[:in] if opts.has_key?(:in)
|
55
52
|
|
56
|
-
|
53
|
+
(opts[:cron] != false && parse_cron(s)) ||
|
54
|
+
(opts[:duration] != false && parse_duration(s)) ||
|
55
|
+
(opts[:at] != false && parse_at(s)) ||
|
56
|
+
(opts[:nat] != false && parse_nat(s)) ||
|
57
|
+
nil
|
57
58
|
end
|
58
59
|
|
59
|
-
def self.
|
60
|
-
def self.do_parse_in(s); do_parse_duration(s); end
|
61
|
-
|
62
|
-
def self.parse(s)
|
60
|
+
def self.do_parse(s, opts={})
|
63
61
|
|
64
|
-
|
62
|
+
parse(s, opts) ||
|
63
|
+
fail(ArgumentError.new("found no time information in #{s.inspect}"))
|
65
64
|
end
|
66
65
|
|
67
|
-
def self.
|
66
|
+
def self.determine_type(s)
|
68
67
|
|
69
|
-
parse(s)
|
70
|
-
|
68
|
+
case self.parse(s)
|
69
|
+
when ::Time then 'at'
|
70
|
+
when ::Fugit::Cron then 'cron'
|
71
|
+
when ::Fugit::Duration then 'in'
|
72
|
+
else nil
|
73
|
+
end
|
71
74
|
end
|
72
75
|
end
|
73
76
|
|
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: 0.9.
|
4
|
+
version: 0.9.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: 2017-01-
|
11
|
+
date: 2017-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: raabro
|
@@ -53,11 +53,11 @@ files:
|
|
53
53
|
- README.md
|
54
54
|
- fugit.gemspec
|
55
55
|
- lib/fugit.rb
|
56
|
-
- lib/fugit/core.rb
|
57
56
|
- lib/fugit/cron.rb
|
58
57
|
- lib/fugit/duration.rb
|
59
58
|
- lib/fugit/misc.rb
|
60
59
|
- lib/fugit/nat.rb
|
60
|
+
- lib/fugit/parse.rb
|
61
61
|
homepage: http://github.com/floraison/fugit
|
62
62
|
licenses:
|
63
63
|
- MIT
|