fugit 1.2.2 → 1.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c85cb2e1a6f9e87e56f09bd46ebc0f23cf41ebc9
4
- data.tar.gz: 2c7c9aeb2e20be568fd41d14bea36aa325077134
3
+ metadata.gz: 4814a18c1285406d94b93d1ae579c0e26f541653
4
+ data.tar.gz: 74fa964320d7596ee309edf6f418f714893ae813
5
5
  SHA512:
6
- metadata.gz: abdc614b1f22423e38cd28d89f3a75b7cb53f5c739f007645fc0957e09fde31b78ffa18ac80c85f3cd178ade3102b917edcc1ef540431be75edfb1db4f81ccb4
7
- data.tar.gz: df991f815915b44e0fb094a7dcda59f1b3e304c03d1b6ea708a8f6bfceedd1873ad481d1cde8f70db32465af2fe7e4cae34789a0e0344393361e98d79cdaa383
6
+ metadata.gz: 1e6039af8e976c6839e34e84f7c2d17eddbde91acd12b91f1f113c2946aac5826a384a55d8fc6d5cdf0042f864ca8ba35882e5a96fc5d04467c0825084641c8a
7
+ data.tar.gz: c02ee46cf23803f967b086bfa14a19137339733bc73a732358c721e6ce88384d7b432fedb7a2dea22f25913c32316a1a1210ca6d63bbf0f600d79ae192b0ec46
@@ -2,6 +2,13 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## fugit 1.2.3 released 2019-07-16
6
+
7
+ * Allow for "from Monday to Friday at 19:22", gh-25
8
+ * Allow for "every Monday to Friday at 18:20", gh-25
9
+ * Allow for "every day at 18:00 and 20:00", gh-24
10
+
11
+
5
12
  ## fugit 1.2.2 released 2019-06-21
6
13
 
7
14
  * Fix Fugit.parse vs "every 15 minutes", gh-22
data/CREDITS.md CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  # fugit credits
3
3
 
4
+ * Shai Coleman https://github.com/shaicoleman parse_nat enhancements, gh-24 and gh-25
4
5
  * Jan Stevens https://github.com/JanStevens Fugit.parse('every 15 minutes') gh-22
5
6
  * Fabio Pitino https://github.com/hspazio nil on February 30 gh-21
6
7
  * Cristian Oneț https://github.com/conet #previous_time vs 1/-1 endless loop gh-15
data/README.md CHANGED
@@ -54,6 +54,39 @@ Fugit.parse('2017-12-12 UTC').class # ==> ::EtOrbi::EoTime
54
54
  Fugit.parse('every day at noon').class # ==> ::Fugit::Cron
55
55
  ```
56
56
 
57
+ If fugit cannot extract a cron, duration or point in time out of the string, it will return nil.
58
+ ```ruby
59
+ Fugit.parse('nada')
60
+ # ==> nil
61
+ ```
62
+
63
+ ## `Fugit.do_parse(s)`
64
+
65
+ `Fugit.do_parse(s)` is equivalent to `Fugit.parse(s)`, but instead of returning nil, it raises an error if the given string contains no time information.
66
+ ```
67
+ Fugit.do_parse('nada')
68
+ # ==> /home/jmettraux/w/fugit/lib/fugit/parse.rb:32
69
+ # :in `do_parse': found no time information in "nada" (ArgumentError)
70
+ ```
71
+
72
+ ## parse_cron, parse_in, parse_at, parse_duration, and parse_nat
73
+
74
+ ```ruby
75
+ require 'fugit'
76
+
77
+ Fugit.parse_cron('0 0 1 jan *').class # ==> ::Fugit::Cron
78
+ Fugit.parse_duration('12y12M').class # ==> ::Fugit::Duration
79
+
80
+ Fugit.parse_at('2017-12-12').class # ==> ::EtOrbi::EoTime
81
+ Fugit.parse_at('2017-12-12 UTC').class # ==> ::EtOrbi::EoTime
82
+
83
+ Fugit.parse_nat('every day at noon').class # ==> ::Fugit::Cron
84
+ ```
85
+
86
+ ## do_parse_cron, do_parse_in, do_parse_at, do_parse_duration, and do_parse_nat
87
+
88
+ As `Fugit.parse(s)` returns nil when it doesn't grok its input, and `Fugit.do_parse(s)` fails when it doesn't grok, each of the `parse_` methods has its partner `do_parse_` method.
89
+
57
90
  ## `Fugit::Cron`
58
91
 
59
92
  A class `Fugit::Cron` to parse cron strings and then `#next_time` and `#previous_time` to compute the next or the previous occurrence respectively.
@@ -199,6 +232,7 @@ Fugit::Nat.parse('every day at 5 pm') # ==> '0 17 * * *'
199
232
  Fugit::Nat.parse('every tuesday at 5 pm') # ==> '0 17 * * 2'
200
233
  Fugit::Nat.parse('every wed at 5 pm') # ==> '0 17 * * 3'
201
234
  Fugit::Nat.parse('every day at 16:30') # ==> '30 16 * * *'
235
+ Fugit::Nat.parse('every day at 16:00 and 18:00') # ==> '0 16,18 * * *'
202
236
  Fugit::Nat.parse('every day at noon') # ==> '0 12 * * *'
203
237
  Fugit::Nat.parse('every day at midnight') # ==> '0 0 * * *'
204
238
  Fugit::Nat.parse('every tuesday and monday at 5pm') # ==> '0 17 * * 1,2'
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Fugit
3
3
 
4
- VERSION = '1.2.2'
4
+ VERSION = '1.2.3'
5
5
  end
6
6
 
7
7
  require 'time'
@@ -8,7 +8,7 @@ module Fugit
8
8
 
9
9
  class << self
10
10
 
11
- def parse(s)
11
+ def parse(s, opts={})
12
12
 
13
13
  return s if s.is_a?(Fugit::Cron) || s.is_a?(Fugit::Duration)
14
14
 
@@ -17,20 +17,23 @@ module Fugit
17
17
  #p s; Raabro.pp(Parser.parse(s, debug: 3), colours: true)
18
18
  a = Parser.parse(s)
19
19
 
20
- if a && a.include?([ :flag, 'every' ])
21
- parse_cron(a)
22
- else
23
- nil
24
- end
20
+ return nil unless a
21
+
22
+ return parse_cron(a, opts) \
23
+ if a.include?([ :flag, 'every' ])
24
+ return parse_cron(a, opts) \
25
+ if a.include?([ :flag, 'from' ]) && a.find { |e| e[0] == :day_range }
26
+
27
+ nil
25
28
  end
26
29
 
27
- def do_parse(s)
30
+ def do_parse(s, opts={})
28
31
 
29
- parse(s) ||
32
+ parse(s, opts) ||
30
33
  fail(ArgumentError.new("could not parse a nat #{s.inspect}"))
31
34
  end
32
35
 
33
- def parse_cron(a)
36
+ def parse_cron(a, opts={})
34
37
 
35
38
  h = { min: nil, hou: [], dom: nil, mon: nil, dow: nil }
36
39
  hkeys = h.keys
@@ -41,10 +44,12 @@ module Fugit
41
44
  elsif key == :simple_hour || key == :numeral_hour
42
45
  h[:hou] << val
43
46
  elsif key == :digital_hour
44
- h[:hou] = [ val[0] ]
45
- h[:min] = [ val[1] ]
47
+ (h[:hou] ||= []) << val[0].to_i
48
+ (h[:min] ||= []) << val[1].to_i
46
49
  elsif key == :name_day
47
50
  (h[:dow] ||= []) << val
51
+ elsif key == :day_range
52
+ (h[:dow] ||= []) << val.collect { |v| v.to_s[0, 3] }.join('-')
48
53
  elsif key == :flag && val == 'pm' && h[:hou]
49
54
  h[:hou][-1] = h[:hou][-1] + 12
50
55
  elsif key == :tz
@@ -54,6 +59,7 @@ module Fugit
54
59
  end
55
60
  end
56
61
  h[:min] ||= [ 0 ]
62
+ h[:min].uniq!
57
63
  h[:hou].sort! if h[:hou]
58
64
  h[:dow].sort! if h[:dow]
59
65
 
@@ -65,9 +71,12 @@ module Fugit
65
71
  a << h[:tz].first if h[:tz]
66
72
  s = a.join(' ')
67
73
 
74
+ #p s
68
75
  Fugit::Cron.parse(s)
69
76
  end
70
77
 
78
+ protected
79
+
71
80
  def process_duration(h, interval, value)
72
81
 
73
82
  send("process_duration_#{interval}", h, value)
@@ -137,6 +146,12 @@ module Fugit
137
146
  def biz_day(i); rex(:biz_day, i, /(biz|business|week) *day/i); end
138
147
  def name_day(i); rex(:name_day, i, /#{WEEKDAYS.reverse.join('|')}/i); end
139
148
 
149
+ def range_sep(i); rex(nil, i, / *- *| +(to|through) +/); end
150
+
151
+ def day_range(i)
152
+ seq(:day_range, i, :name_day, :range_sep, :name_day)
153
+ end
154
+
140
155
  def _tz_name(i)
141
156
  rex(nil, i, /[A-Z][a-zA-Z0-9+\-]+(\/[A-Z][a-zA-Z0-9+\-_]+){0,2}/)
142
157
  end
@@ -155,10 +170,11 @@ module Fugit
155
170
  /ix)
156
171
  end
157
172
 
158
- def flag(i); rex(:flag, i, /(every|at|after|am|pm|on|in)/i); end
173
+ def flag(i); rex(:flag, i, /(every|from|at|after|am|pm|on|in)/i); end
159
174
 
160
175
  def datum(i)
161
176
  alt(nil, i,
177
+ :day_range,
162
178
  :plain_day, :biz_day, :name_day,
163
179
  :_tz,
164
180
  :flag,
@@ -199,6 +215,8 @@ module Fugit
199
215
  [ :digital_hour, NHOURS[v] ]
200
216
  when :name_day
201
217
  [ k, WEEKDAYS.index(v[0, 3]) ]
218
+ when :day_range
219
+ [ k, tt.subgather(nil).collect { |st| st.string.downcase } ]
202
220
  else
203
221
  [ k, v ]
204
222
  end }
@@ -5,13 +5,13 @@ module Fugit
5
5
 
6
6
  def parse_cron(s); ::Fugit::Cron.parse(s); end
7
7
  def parse_duration(s); ::Fugit::Duration.parse(s); end
8
- def parse_nat(s); ::Fugit::Nat.parse(s); end
8
+ def parse_nat(s, opts={}); ::Fugit::Nat.parse(s, opts); end
9
9
  def parse_at(s); ::Fugit::At.parse(s); end
10
10
  def parse_in(s); parse_duration(s); end
11
11
 
12
12
  def do_parse_cron(s); ::Fugit::Cron.do_parse(s); end
13
13
  def do_parse_duration(s); ::Fugit::Duration.do_parse(s); end
14
- def do_parse_nat(s); ::Fugit::Nat.do_parse(s); end
14
+ def do_parse_nat(s, opts={}); ::Fugit::Nat.do_parse(s, opts); end
15
15
  def do_parse_at(s); ::Fugit::At.do_parse(s); end
16
16
  def do_parse_in(s); do_parse_duration(s); end
17
17
 
@@ -21,7 +21,7 @@ module Fugit
21
21
 
22
22
  (opts[:cron] != false && parse_cron(s)) ||
23
23
  (opts[:duration] != false && parse_duration(s)) ||
24
- (opts[:nat] != false && parse_nat(s)) ||
24
+ (opts[:nat] != false && parse_nat(s, opts)) ||
25
25
  (opts[:at] != false && parse_at(s)) ||
26
26
  nil
27
27
  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.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-21 00:00:00.000000000 Z
11
+ date: 2019-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: raabro