fugit 1.1.3 → 1.1.4
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/CHANGELOG.md +8 -0
- data/CREDITS.md +2 -0
- data/Makefile +6 -2
- data/README.md +17 -11
- data/fugit.gemspec +1 -1
- data/lib/fugit.rb +1 -1
- data/lib/fugit/at.rb +8 -5
- data/lib/fugit/cron.rb +17 -2
- data/lib/fugit/duration.rb +45 -45
- data/lib/fugit/misc.rb +20 -17
- data/lib/fugit/nat.rb +103 -42
- data/lib/fugit/parse.rb +35 -32
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d3a2d6e072a2ae0ce68473054ef7701ce45a4867
|
|
4
|
+
data.tar.gz: a1c5e3b9c36b2ee907d617943b5baff6de9005a4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2c1cc2399627c451105219913f9668dfbd55ea77259e8fad5a356da4d828bd136bb72de28446451bf77bbf7455f62c8a73ec25f59d3426b89cd438382ee2a973
|
|
7
|
+
data.tar.gz: bb30951b92097750810dc700fa0d5d80ade2bc80d5da398776b9f554db3e889e4086c52fd412ba33bacb5f2d66742b3726aa6a694f64653a12780e76970b0e30
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
# fugit CHANGELOG.md
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
## fugit 1.1.4 released 2018-07-20
|
|
6
|
+
|
|
7
|
+
* Add duration support for Fugit::Nat (@cristianbica gh-7)
|
|
8
|
+
* Fix Duration not correctly parsing minutes and seconds long format (@cristianbica gh-7)
|
|
9
|
+
* Add timezone support for Fugit::Nat (@cristianbica gh-7)
|
|
10
|
+
* Use timezone name when converting a Fugit::Cron to cron string (@cristianbica gh-7)
|
|
11
|
+
|
|
12
|
+
|
|
5
13
|
## fugit 1.1.3 released 2018-06-21
|
|
6
14
|
|
|
7
15
|
* Silenced Ruby warnings (Utilum in gh-4)
|
data/CREDITS.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
# fugit credits
|
|
3
3
|
|
|
4
|
+
* jakemack https://github.com/jakemack issue when going out of DST, gh-6
|
|
5
|
+
* Cristian Bica https://github.com/cristianbica Nat improvements, gh-7
|
|
4
6
|
* Utilum https://github.com/utilum silenced Ruby warnings
|
|
5
7
|
* Tero Marttila https://github.com/SpComb added missing Cron#seconds
|
|
6
8
|
* Harry Lascelles https://github.com/hlascelles timezone reminder
|
data/Makefile
CHANGED
|
@@ -13,7 +13,7 @@ cl: count_lines
|
|
|
13
13
|
|
|
14
14
|
gemspec_validate:
|
|
15
15
|
@echo "---"
|
|
16
|
-
ruby -e "s = eval(File.read(Dir['*.gemspec'].first)); s.validate"
|
|
16
|
+
ruby -e "s = eval(File.read(Dir['*.gemspec'].first)); p s.validate"
|
|
17
17
|
@echo "---"
|
|
18
18
|
|
|
19
19
|
name: gemspec_validate
|
|
@@ -30,6 +30,10 @@ build: gemspec_validate
|
|
|
30
30
|
push: build
|
|
31
31
|
gem push pkg/$(NAME)-$(VERSION).gem
|
|
32
32
|
|
|
33
|
+
spec:
|
|
34
|
+
bundle exec rspec
|
|
35
|
+
test: spec
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
|
|
38
|
+
.PHONY: count_lines gemspec_validate name cw build push spec
|
|
35
39
|
|
data/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Time tools for [flor](https://github.com/floraison/flor) and the floraison group
|
|
|
8
8
|
|
|
9
9
|
It uses [et-orbi](https://github.com/floraison/et-orbi) to represent time instances and [raabro](https://github.com/floraison/raabro) as a basis for its parsers.
|
|
10
10
|
|
|
11
|
-
Fugit
|
|
11
|
+
Fugit is a core dependency of [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler) 3.5.x.
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
## Related projects
|
|
@@ -156,16 +156,22 @@ Fugit understand some kind of "natural" language:
|
|
|
156
156
|
|
|
157
157
|
For example, those "every" get turned into `Fugit::Cron` instances:
|
|
158
158
|
```ruby
|
|
159
|
-
Fugit::Nat.parse('every day at five')
|
|
160
|
-
Fugit::Nat.parse('every weekday at five')
|
|
161
|
-
Fugit::Nat.parse('every day at 5 pm')
|
|
162
|
-
Fugit::Nat.parse('every tuesday at 5 pm')
|
|
163
|
-
Fugit::Nat.parse('every wed at 5 pm')
|
|
164
|
-
Fugit::Nat.parse('every day at 16:30')
|
|
165
|
-
Fugit::Nat.parse('every day at noon')
|
|
166
|
-
Fugit::Nat.parse('every day at midnight')
|
|
167
|
-
Fugit::Nat.parse('every tuesday and monday at 5pm')
|
|
168
|
-
Fugit::Nat.parse('every wed or Monday at 5pm and 11')
|
|
159
|
+
Fugit::Nat.parse('every day at five') # ==> '0 5 * * *'
|
|
160
|
+
Fugit::Nat.parse('every weekday at five') # ==> '0 5 * * 1,2,3,4,5'
|
|
161
|
+
Fugit::Nat.parse('every day at 5 pm') # ==> '0 17 * * *'
|
|
162
|
+
Fugit::Nat.parse('every tuesday at 5 pm') # ==> '0 17 * * 2'
|
|
163
|
+
Fugit::Nat.parse('every wed at 5 pm') # ==> '0 17 * * 3'
|
|
164
|
+
Fugit::Nat.parse('every day at 16:30') # ==> '30 16 * * *'
|
|
165
|
+
Fugit::Nat.parse('every day at noon') # ==> '0 12 * * *'
|
|
166
|
+
Fugit::Nat.parse('every day at midnight') # ==> '0 0 * * *'
|
|
167
|
+
Fugit::Nat.parse('every tuesday and monday at 5pm') # ==> '0 17 * * 1,2'
|
|
168
|
+
Fugit::Nat.parse('every wed or Monday at 5pm and 11') # ==> '0 11,17 * * 1,3'
|
|
169
|
+
Fugit::Nat.parse('every day at 5 pm on America/Los_Angeles') # ==> '0 17 * * * America/Los_Angeles'
|
|
170
|
+
Fugit::Nat.parse('every day at 6 pm in Asia/Tokyo') # ==> '0 18 * * * Asia/Tokyo'
|
|
171
|
+
Fugit::Nat.parse('every 3 hours') # ==> '0 */3 * * *'
|
|
172
|
+
Fugit::Nat.parse('every 4 months') # ==> '0 0 1 */4 *'
|
|
173
|
+
Fugit::Nat.parse('every 5 minutes') # ==> '*/5 * * * *'
|
|
174
|
+
Fugit::Nat.parse('every 15s') # ==> '*/15 * * * * *'
|
|
169
175
|
```
|
|
170
176
|
|
|
171
177
|
Directly with `Fugit.parse(s)` is OK too:
|
data/fugit.gemspec
CHANGED
|
@@ -29,7 +29,7 @@ Time tools for flor and the floraison project. Cron parsing and occurrence compu
|
|
|
29
29
|
|
|
30
30
|
#s.add_runtime_dependency 'tzinfo'
|
|
31
31
|
s.add_runtime_dependency 'raabro', '~> 1.1'
|
|
32
|
-
s.add_runtime_dependency 'et-orbi', '~> 1.1', '>= 1.1.
|
|
32
|
+
s.add_runtime_dependency 'et-orbi', '~> 1.1', '>= 1.1.3'
|
|
33
33
|
|
|
34
34
|
s.add_development_dependency 'rspec', '~> 3.7'
|
|
35
35
|
|
data/lib/fugit.rb
CHANGED
data/lib/fugit/at.rb
CHANGED
|
@@ -3,14 +3,17 @@ module Fugit
|
|
|
3
3
|
|
|
4
4
|
module At
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
class << self
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
def parse(s)
|
|
9
|
+
|
|
10
|
+
::EtOrbi.make_time(s) rescue nil
|
|
11
|
+
end
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
def do_parse(s)
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
::EtOrbi.make_time(s)
|
|
16
|
+
end
|
|
14
17
|
end
|
|
15
18
|
end
|
|
16
19
|
end
|
data/lib/fugit/cron.rb
CHANGED
|
@@ -57,7 +57,7 @@ module Fugit
|
|
|
57
57
|
(@monthdays || [ '*' ]).join(','),
|
|
58
58
|
(@months || [ '*' ]).join(','),
|
|
59
59
|
(@weekdays || [ [ '*' ] ]).map { |d| d.compact.join('#') }.join(','),
|
|
60
|
-
@timezone ? @timezone.
|
|
60
|
+
@timezone ? @timezone.name : nil
|
|
61
61
|
].compact.join(' ')
|
|
62
62
|
end
|
|
63
63
|
end
|
|
@@ -169,20 +169,35 @@ module Fugit
|
|
|
169
169
|
def next_time(from=::EtOrbi::EoTime.now)
|
|
170
170
|
|
|
171
171
|
from = ::EtOrbi.make_time(from)
|
|
172
|
+
sfrom = from.strftime('%F/%T')
|
|
173
|
+
|
|
172
174
|
t = TimeCursor.new(from.translate(@timezone))
|
|
175
|
+
#
|
|
176
|
+
# the translation occurs in the timezone of
|
|
177
|
+
# this Fugit::Cron instance
|
|
173
178
|
|
|
174
179
|
loop do
|
|
175
|
-
|
|
180
|
+
|
|
176
181
|
(from.to_i == t.to_i) && (t.inc(1); next)
|
|
177
182
|
month_match?(t) || (t.inc_month; next)
|
|
178
183
|
day_match?(t) || (t.inc_day; next)
|
|
179
184
|
hour_match?(t) || (t.inc_hour; next)
|
|
180
185
|
min_match?(t) || (t.inc_min; next)
|
|
181
186
|
sec_match?(t) || (t.inc_sec(@seconds); next)
|
|
187
|
+
|
|
188
|
+
st = t.time.strftime('%F/%T')
|
|
189
|
+
(from, sfrom = t.time, st; next) if st == sfrom
|
|
190
|
+
#
|
|
191
|
+
# when transitioning out of DST, this prevents #next_time from
|
|
192
|
+
# yielding the same literal time twice in a row, see gh-6
|
|
193
|
+
|
|
182
194
|
break
|
|
183
195
|
end
|
|
184
196
|
|
|
185
197
|
t.time.translate(from.zone)
|
|
198
|
+
#
|
|
199
|
+
# the answer time is in the same timezone as the `from`
|
|
200
|
+
# starting point
|
|
186
201
|
end
|
|
187
202
|
|
|
188
203
|
def previous_time(from=::EtOrbi::EoTime.now)
|
data/lib/fugit/duration.rb
CHANGED
|
@@ -5,40 +5,58 @@ module Fugit
|
|
|
5
5
|
|
|
6
6
|
attr_reader :original, :h, :options
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
class << self
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
def new(s)
|
|
11
|
+
|
|
12
|
+
parse(s)
|
|
13
|
+
end
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
def parse(s, opts={})
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
return s if s.is_a?(self)
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
original = s
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
s = "#{s}s" if s.is_a?(Numeric)
|
|
20
22
|
|
|
21
|
-
|
|
23
|
+
return nil unless s.is_a?(String)
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
s = s.strip
|
|
24
26
|
#p [ original, s ]; Raabro.pp(Parser.parse(s, debug: 3), colours: true)
|
|
25
27
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
#p h
|
|
28
|
+
h =
|
|
29
|
+
if opts[:iso]
|
|
30
|
+
IsoParser.parse(opts[:stricter] ? s : s.upcase)
|
|
31
|
+
elsif opts[:plain]
|
|
32
|
+
Parser.parse(s)
|
|
33
|
+
else
|
|
34
|
+
Parser.parse(s) || IsoParser.parse(opts[:stricter] ? s : s.upcase)
|
|
35
|
+
end
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
h ? self.allocate.send(:init, original, opts, h) : nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def do_parse(s, opts={})
|
|
41
|
+
|
|
42
|
+
parse(s, opts) ||
|
|
43
|
+
fail(ArgumentError.new("not a duration #{s.inspect}"))
|
|
44
|
+
end
|
|
38
45
|
|
|
39
|
-
|
|
46
|
+
def to_plain_s(o); do_parse(o).deflate.to_plain_s; end
|
|
47
|
+
def to_iso_s(o); do_parse(o).deflate.to_iso_s; end
|
|
48
|
+
def to_long_s(o, opts={}); do_parse(o).deflate.to_long_s(opts); end
|
|
40
49
|
|
|
41
|
-
|
|
50
|
+
def common_rewrite_dur(t)
|
|
51
|
+
|
|
52
|
+
t
|
|
53
|
+
.subgather(nil)
|
|
54
|
+
.inject({}) { |h, tt|
|
|
55
|
+
v = tt.string; v = v.index('.') ? v.to_f : v.to_i
|
|
56
|
+
# drops ending ("y", "m", ...) by itself
|
|
57
|
+
h[tt.name] = (h[tt.name] || 0) + v
|
|
58
|
+
h }
|
|
59
|
+
end
|
|
42
60
|
end
|
|
43
61
|
|
|
44
62
|
KEYS = {
|
|
@@ -103,12 +121,6 @@ module Fugit
|
|
|
103
121
|
s.string
|
|
104
122
|
end
|
|
105
123
|
|
|
106
|
-
class << self
|
|
107
|
-
def to_plain_s(o); do_parse(o).deflate.to_plain_s; end
|
|
108
|
-
def to_iso_s(o); do_parse(o).deflate.to_iso_s; end
|
|
109
|
-
def to_long_s(o, opts={}); do_parse(o).deflate.to_long_s(opts); end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
124
|
# For now, let's alias to #h
|
|
113
125
|
#
|
|
114
126
|
def to_h; h; end
|
|
@@ -308,18 +320,6 @@ module Fugit
|
|
|
308
320
|
self
|
|
309
321
|
end
|
|
310
322
|
|
|
311
|
-
def self.common_rewrite_dur(t)
|
|
312
|
-
|
|
313
|
-
t
|
|
314
|
-
.subgather(nil)
|
|
315
|
-
.inject({}) { |h, tt|
|
|
316
|
-
v = tt.string; v = v.index('.') ? v.to_f : v.to_i
|
|
317
|
-
# drops ending ("y", "m", ...) by itself
|
|
318
|
-
h[tt.name] = (h[tt.name] || 0) + v
|
|
319
|
-
h
|
|
320
|
-
}
|
|
321
|
-
end
|
|
322
|
-
|
|
323
323
|
module Parser include Raabro
|
|
324
324
|
|
|
325
325
|
# piece parsers bottom to top
|
|
@@ -328,12 +328,12 @@ module Fugit
|
|
|
328
328
|
|
|
329
329
|
def yea(i); rex(:yea, i, /(\d+\.\d*|(\d*\.)?\d+) *y(ears?)?/i); end
|
|
330
330
|
def mon(i); rex(:mon, i, /(\d+\.\d*|(\d*\.)?\d+) *(M|months?)/); end
|
|
331
|
-
def wee(i); rex(:wee, i, /(\d+\.\d*|(\d*\.)?\d+) *(
|
|
332
|
-
def day(i); rex(:day, i, /(\d+\.\d*|(\d*\.)?\d+) *(
|
|
333
|
-
def hou(i); rex(:hou, i, /(\d+\.\d*|(\d*\.)?\d+) *(
|
|
334
|
-
def min(i); rex(:min, i, /(\d+\.\d*|(\d*\.)?\d+) *(
|
|
331
|
+
def wee(i); rex(:wee, i, /(\d+\.\d*|(\d*\.)?\d+) *w(eeks?)?/i); end
|
|
332
|
+
def day(i); rex(:day, i, /(\d+\.\d*|(\d*\.)?\d+) *d(ays?)?/i); end
|
|
333
|
+
def hou(i); rex(:hou, i, /(\d+\.\d*|(\d*\.)?\d+) *h(ours?)?/i); end
|
|
334
|
+
def min(i); rex(:min, i, /(\d+\.\d*|(\d*\.)?\d+) *m(in(ute)?s?)?/); end
|
|
335
335
|
|
|
336
|
-
def sec(i); rex(:sec, i, /(\d+\.\d*|(\d*\.)?\d+) *(
|
|
336
|
+
def sec(i); rex(:sec, i, /(\d+\.\d*|(\d*\.)?\d+) *s(ec(ond)?)?s?/i); end
|
|
337
337
|
def sek(i); rex(:sec, i, /(\d+\.\d*|\.\d+|\d+)$/); end
|
|
338
338
|
|
|
339
339
|
def elt(i); alt(nil, i, :yea, :mon, :wee, :day, :hou, :min, :sec, :sek); end
|
data/lib/fugit/misc.rb
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
|
|
2
2
|
module Fugit
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
class << self
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
s = StringIO.new
|
|
6
|
+
def isostamp(show_date, show_time, show_usec, time)
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
s << sprintf('.%06d', t.usec) if show_time && show_usec
|
|
12
|
-
s << 'Z' if show_time && time.utc?
|
|
8
|
+
t = time || Time.now
|
|
9
|
+
s = StringIO.new
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
s << t.strftime('%Y-%m-%d') if show_date
|
|
12
|
+
s << t.strftime('T%H:%M:%S') if show_time
|
|
13
|
+
s << sprintf('.%06d', t.usec) if show_time && show_usec
|
|
14
|
+
s << 'Z' if show_time && time.utc?
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
s.string
|
|
17
|
+
end
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
end
|
|
19
|
+
def time_to_s(t)
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
isostamp(true, true, false, t)
|
|
22
|
+
end
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
def time_to_plain_s(t=Time.now, z=true)
|
|
25
|
+
|
|
26
|
+
t.strftime('%Y-%m-%d %H:%M:%S') + (z && t.utc? ? ' Z' : '')
|
|
27
|
+
end
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
def time_to_zone_s(t=Time.now)
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
t.strftime('%Y-%m-%d %H:%M:%S %Z %z')
|
|
32
|
+
end
|
|
30
33
|
end
|
|
31
34
|
end
|
|
32
35
|
|
data/lib/fugit/nat.rb
CHANGED
|
@@ -6,52 +6,93 @@ module Fugit
|
|
|
6
6
|
#
|
|
7
7
|
module Nat
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
class << self
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
def parse(s)
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
return s if s.is_a?(Fugit::Cron) || s.is_a?(Fugit::Duration)
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
a = Parser.parse(s)
|
|
15
|
+
return nil unless s.is_a?(String)
|
|
17
16
|
|
|
18
|
-
#p
|
|
19
|
-
|
|
17
|
+
#p s; Raabro.pp(Parser.parse(s, debug: 3), colours: true)
|
|
18
|
+
a = Parser.parse(s)
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
if a && a.include?([ :flag, 'every' ])
|
|
21
|
+
parse_cron(a)
|
|
22
|
+
else
|
|
23
|
+
nil
|
|
24
|
+
end
|
|
25
25
|
end
|
|
26
|
-
end
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
def do_parse(s)
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
parse(s) ||
|
|
30
|
+
fail(ArgumentError.new("could not parse a nat #{s.inspect}"))
|
|
31
|
+
end
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
def parse_cron(a)
|
|
34
|
+
|
|
35
|
+
h = { min: nil, hou: [], dom: [ nil ], mon: [ nil ], dow: [ nil ] }
|
|
36
|
+
|
|
37
|
+
a.each do |key, val|
|
|
38
|
+
if key == :biz_day
|
|
39
|
+
h[:dow] = [ [ 1, 5 ] ]
|
|
40
|
+
elsif key == :simple_hour || key == :numeral_hour
|
|
41
|
+
(h[:hou] ||= []) << [ val ]
|
|
42
|
+
elsif key == :digital_hour
|
|
43
|
+
h[:hou] = [ val[0, 1] ]
|
|
44
|
+
h[:min] = [ val[1, 1] ]
|
|
45
|
+
elsif key == :name_day
|
|
46
|
+
(h[:dow] ||= []) << [ val ]
|
|
47
|
+
elsif key == :flag && val == 'pm' && h[:hou]
|
|
48
|
+
h[:hou][-1] = [ h[:hou][-1].first + 12 ]
|
|
49
|
+
elsif key == :tz
|
|
50
|
+
h[:tz] = val
|
|
51
|
+
elsif key == :duration
|
|
52
|
+
process_duration(h, *val[0].to_h.first)
|
|
53
|
+
end
|
|
49
54
|
end
|
|
55
|
+
h[:min] ||= [ 0 ]
|
|
56
|
+
h[:dow].sort_by! { |d, _| d || 0 }
|
|
57
|
+
|
|
58
|
+
Fugit::Cron.allocate.send(:init, nil, h)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def process_duration(h, interval, value)
|
|
62
|
+
|
|
63
|
+
send("process_duration_#{interval}", h, value)
|
|
50
64
|
end
|
|
51
|
-
h[:min] ||= [ 0 ]
|
|
52
|
-
h[:dow].sort_by! { |d, _| d || 0 }
|
|
53
65
|
|
|
54
|
-
|
|
66
|
+
def process_duration_mon(h, value)
|
|
67
|
+
|
|
68
|
+
h[:hou] = [ 0 ]
|
|
69
|
+
h[:dom] = [ 1 ]
|
|
70
|
+
h[:mon] = [ value == 1 ? '*' : "*/#{value}" ]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def process_duration_day(h, value)
|
|
74
|
+
|
|
75
|
+
h[:hou] = [ 0 ]
|
|
76
|
+
h[:dom] = [ value == 1 ? '*' : "*/#{value}" ]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def process_duration_hou(h, value)
|
|
80
|
+
|
|
81
|
+
h[:hou] = [ value == 1 ? '*' : "*/#{value}" ]
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def process_duration_min(h, value)
|
|
85
|
+
|
|
86
|
+
h[:hou] = [ '*' ]
|
|
87
|
+
h[:min] = [ value == 1 ? '*' : "*/#{value}" ]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def process_duration_sec(h, value)
|
|
91
|
+
|
|
92
|
+
h[:hou] = [ '*' ]
|
|
93
|
+
h[:min] = [ '*' ]
|
|
94
|
+
h[:sec] = [ value == 1 ? '*' : "*/#{value}" ]
|
|
95
|
+
end
|
|
55
96
|
end
|
|
56
97
|
|
|
57
98
|
module Parser include Raabro
|
|
@@ -81,20 +122,37 @@ module Fugit
|
|
|
81
122
|
def name_hour(i)
|
|
82
123
|
rex(:name_hour, i, /(#{NHOURS.keys.join('|')})/i)
|
|
83
124
|
end
|
|
84
|
-
def hour(i)
|
|
85
|
-
alt(nil, i, :numeral_hour, :name_hour, :digital_hour, :simple_hour);
|
|
86
|
-
end
|
|
87
125
|
|
|
88
126
|
def plain_day(i); rex(:plain_day, i, /day/i); end
|
|
89
127
|
def biz_day(i); rex(:biz_day, i, /(biz|business|week) *day/i); end
|
|
90
128
|
def name_day(i); rex(:name_day, i, /#{WEEKDAYS.reverse.join('|')}/i); end
|
|
91
129
|
|
|
92
|
-
def
|
|
130
|
+
def _tz_name(i)
|
|
131
|
+
rex(nil, i, /[A-Z][a-zA-Z0-9]+(\/[A-Z][a-zA-Z0-9\_]+){0,2}/)
|
|
132
|
+
end
|
|
133
|
+
def _tz_delta(i)
|
|
134
|
+
rex(nil, i, /[-+]([01][0-9]|2[0-4]):?(00|15|30|45)/)
|
|
135
|
+
end
|
|
136
|
+
def _tz(i); alt(:tz, i, :_tz_delta, :_tz_name); end
|
|
137
|
+
|
|
138
|
+
def duration(i)
|
|
139
|
+
rex(
|
|
140
|
+
:duration, i,
|
|
141
|
+
/
|
|
142
|
+
\d+
|
|
143
|
+
\s?
|
|
144
|
+
(mon(ths?)?|d(ays?)?|h(ours?)?|m(in(ute)?s?)?|s(ec(ond)?s?)?)
|
|
145
|
+
/ix)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def flag(i); rex(:flag, i, /(every|at|after|am|pm|on|in)/i); end
|
|
93
149
|
|
|
94
150
|
def datum(i)
|
|
95
151
|
alt(nil, i,
|
|
96
|
-
:flag,
|
|
97
152
|
:plain_day, :biz_day, :name_day,
|
|
153
|
+
:_tz,
|
|
154
|
+
:flag,
|
|
155
|
+
:duration,
|
|
98
156
|
:name_hour, :numeral_hour, :digital_hour, :simple_hour)
|
|
99
157
|
end
|
|
100
158
|
|
|
@@ -107,7 +165,7 @@ module Fugit
|
|
|
107
165
|
|
|
108
166
|
def rewrite_nat(t)
|
|
109
167
|
|
|
110
|
-
#Raabro.pp(t)
|
|
168
|
+
#Raabro.pp(t, colours: true)
|
|
111
169
|
t
|
|
112
170
|
.subgather(nil)
|
|
113
171
|
.collect { |tt|
|
|
@@ -116,6 +174,10 @@ module Fugit
|
|
|
116
174
|
v = tt.string.downcase
|
|
117
175
|
|
|
118
176
|
case k
|
|
177
|
+
when :tz
|
|
178
|
+
[ k, [ tt.string.strip, EtOrbi.get_tzone(tt.string.strip) ] ]
|
|
179
|
+
when :duration
|
|
180
|
+
[ k, [ Fugit::Duration.parse(tt.string.strip) ] ]
|
|
119
181
|
when :numeral_hour
|
|
120
182
|
[ k, NUMS.index(v) ]
|
|
121
183
|
when :simple_hour
|
|
@@ -129,8 +191,7 @@ module Fugit
|
|
|
129
191
|
[ k, WEEKDAYS.index(v[0, 3]) ]
|
|
130
192
|
else
|
|
131
193
|
[ k, v ]
|
|
132
|
-
end
|
|
133
|
-
}
|
|
194
|
+
end }
|
|
134
195
|
end
|
|
135
196
|
end
|
|
136
197
|
end
|
data/lib/fugit/parse.rb
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
1
|
|
|
2
2
|
module Fugit
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
def self.parse_duration(s); ::Fugit::Duration.parse(s); end
|
|
6
|
-
def self.parse_nat(s); ::Fugit::Nat.parse(s); end
|
|
7
|
-
def self.parse_at(s); ::Fugit::At.parse(s); end
|
|
8
|
-
def self.parse_in(s); parse_duration(s); end
|
|
9
|
-
|
|
10
|
-
def self.do_parse_cron(s); ::Fugit::Cron.do_parse(s); end
|
|
11
|
-
def self.do_parse_duration(s); ::Fugit::Duration.do_parse(s); end
|
|
12
|
-
def self.do_parse_nat(s); ::Fugit::Nat.do_parse(s); end
|
|
13
|
-
def self.do_parse_at(s); ::Fugit::At.do_parse(s); end
|
|
14
|
-
def self.do_parse_in(s); do_parse_duration(s); end
|
|
15
|
-
|
|
16
|
-
def self.parse(s, opts={})
|
|
17
|
-
|
|
18
|
-
opts[:at] = opts[:in] if opts.has_key?(:in)
|
|
19
|
-
|
|
20
|
-
(opts[:cron] != false && parse_cron(s)) ||
|
|
21
|
-
(opts[:duration] != false && parse_duration(s)) ||
|
|
22
|
-
(opts[:at] != false && parse_at(s)) ||
|
|
23
|
-
(opts[:nat] != false && parse_nat(s)) ||
|
|
24
|
-
nil
|
|
25
|
-
end
|
|
4
|
+
class << self
|
|
26
5
|
|
|
27
|
-
|
|
6
|
+
def parse_cron(s); ::Fugit::Cron.parse(s); end
|
|
7
|
+
def parse_duration(s); ::Fugit::Duration.parse(s); end
|
|
8
|
+
def parse_nat(s); ::Fugit::Nat.parse(s); end
|
|
9
|
+
def parse_at(s); ::Fugit::At.parse(s); end
|
|
10
|
+
def parse_in(s); parse_duration(s); end
|
|
28
11
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
def do_parse_cron(s); ::Fugit::Cron.do_parse(s); end
|
|
13
|
+
def do_parse_duration(s); ::Fugit::Duration.do_parse(s); end
|
|
14
|
+
def do_parse_nat(s); ::Fugit::Nat.do_parse(s); end
|
|
15
|
+
def do_parse_at(s); ::Fugit::At.do_parse(s); end
|
|
16
|
+
def do_parse_in(s); do_parse_duration(s); end
|
|
17
|
+
|
|
18
|
+
def parse(s, opts={})
|
|
19
|
+
|
|
20
|
+
opts[:at] = opts[:in] if opts.has_key?(:in)
|
|
21
|
+
|
|
22
|
+
(opts[:cron] != false && parse_cron(s)) ||
|
|
23
|
+
(opts[:duration] != false && parse_duration(s)) ||
|
|
24
|
+
(opts[:at] != false && parse_at(s)) ||
|
|
25
|
+
(opts[:nat] != false && parse_nat(s)) ||
|
|
26
|
+
nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def do_parse(s, opts={})
|
|
30
|
+
|
|
31
|
+
parse(s, opts) ||
|
|
32
|
+
fail(ArgumentError.new("found no time information in #{s.inspect}"))
|
|
33
|
+
end
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
def determine_type(s)
|
|
34
36
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
case self.parse(s)
|
|
38
|
+
when ::Fugit::Cron then 'cron'
|
|
39
|
+
when ::Fugit::Duration then 'in'
|
|
40
|
+
when ::Time, ::EtOrbi::EoTime then 'at'
|
|
41
|
+
else nil
|
|
42
|
+
end
|
|
40
43
|
end
|
|
41
44
|
end
|
|
42
45
|
end
|
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.4
|
|
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-
|
|
11
|
+
date: 2018-07-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: raabro
|
|
@@ -33,7 +33,7 @@ dependencies:
|
|
|
33
33
|
version: '1.1'
|
|
34
34
|
- - ">="
|
|
35
35
|
- !ruby/object:Gem::Version
|
|
36
|
-
version: 1.1.
|
|
36
|
+
version: 1.1.3
|
|
37
37
|
type: :runtime
|
|
38
38
|
prerelease: false
|
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -43,7 +43,7 @@ dependencies:
|
|
|
43
43
|
version: '1.1'
|
|
44
44
|
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: 1.1.
|
|
46
|
+
version: 1.1.3
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
48
|
name: rspec
|
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
99
99
|
version: '0'
|
|
100
100
|
requirements: []
|
|
101
101
|
rubyforge_project:
|
|
102
|
-
rubygems_version: 2.5.2
|
|
102
|
+
rubygems_version: 2.5.2.3
|
|
103
103
|
signing_key:
|
|
104
104
|
specification_version: 4
|
|
105
105
|
summary: time tools for flor
|