fugit 1.5.3 → 1.8.1
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 +35 -0
- data/CREDITS.md +8 -1
- data/LICENSE.txt +1 -1
- data/README.md +78 -2
- data/fugit.gemspec +1 -1
- data/lib/fugit/cron.rb +29 -15
- data/lib/fugit/duration.rb +6 -4
- data/lib/fugit/nat.rb +36 -16
- data/lib/fugit/parse.rb +13 -0
- data/lib/fugit.rb +1 -1
- metadata +6 -7
- data/Makefile +0 -55
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1839fa07acc6287be95f8076c19afa2c9d6c9b5500ac1b03febab61959b5057
|
4
|
+
data.tar.gz: 839ff5c0f85ccd51625febfdbfedd017e46962d288cf313307b706830dc838c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5336bf251441fa3f7372d48aec2196cf86831b24c64110955f2ccf2df2e6e1ec84a68b318b53be8282f87794f40c09778bddd47abec3f65fe1469544a758fabb
|
7
|
+
data.tar.gz: 0fdd70455097838c21c3f03c9dca20889b4aba07f67d790136e40be2d8686b0a6ad8a594fff1fe28e7cd4d322ad66a8a31aa71750cd435c7601345487ae89bdb
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,41 @@
|
|
2
2
|
# CHANGELOG.md
|
3
3
|
|
4
4
|
|
5
|
+
## fugit 1.8.1 released 2023-01-20
|
6
|
+
|
7
|
+
* Fix for month subtraction, gh-84, @mreinsch
|
8
|
+
* Fix duration - time, gh-85, @mreinsch
|
9
|
+
|
10
|
+
|
11
|
+
## fugit 1.8.0 released 2022-12-06
|
12
|
+
|
13
|
+
* Introduce Fugit.parse_cronish and .do_parse_cronish, gh-70
|
14
|
+
|
15
|
+
|
16
|
+
## fugit 1.7.2 released 2022-11-03
|
17
|
+
|
18
|
+
* Fix 'every day at 12:15 am', gh-81
|
19
|
+
* Fix 'every day at 5:00pm', gh-81
|
20
|
+
|
21
|
+
|
22
|
+
## fugit 1.7.1 released 2022-09-21
|
23
|
+
|
24
|
+
* Change behaviour for "0 0/5 * * *", gh-79
|
25
|
+
go "every 5h start hour 0", previous behaviour only triggered at hour 0
|
26
|
+
|
27
|
+
|
28
|
+
## fugit 1.7.0 released 2022-09-15
|
29
|
+
|
30
|
+
* Introduce the & cron syntax (day-of-month AND day-of-week), gh-78
|
31
|
+
* Change how cron deals with modulo and offset, gh-76
|
32
|
+
* Be liberal with extra commas, gh-77
|
33
|
+
|
34
|
+
|
35
|
+
## fugit 1.6.0 release 2022-08-25
|
36
|
+
|
37
|
+
* Ensure input strings are stripped before parsing, gh-74
|
38
|
+
|
39
|
+
|
5
40
|
## fugit 1.5.3 released 2022-04-02
|
6
41
|
|
7
42
|
* Fix Fugit::Cron.to_s vs "0 13 * * wed%2", gh-68
|
data/CREDITS.md
CHANGED
@@ -1,7 +1,14 @@
|
|
1
1
|
|
2
2
|
# fugit credits
|
3
3
|
|
4
|
-
*
|
4
|
+
* Michael Reinsch, https://github.com/mreinsch, gh-84 and gh-85
|
5
|
+
* Marc Anguera, https://github.com/markets, gh-70 and Sidekiq-Cron
|
6
|
+
* ski-nine, https://github.com/ski-nine, gh-81
|
7
|
+
* Joseph Halter, https://github.com/JosephHalter, gh-79
|
8
|
+
* James Healy, https://github.com/yob, gh-76
|
9
|
+
* John Bachir, https://github.com/jjb, gh-74
|
10
|
+
* Vivek Miyani, https://github.com/vivekmiyani, gh-71
|
11
|
+
* Peter Goldstein, https://github.com/petergoldstein infra, gh-65, -72
|
5
12
|
* Pascal Zumkehr https://github.com/codez gh-62, Santiago into DST vs Time.zone
|
6
13
|
* Ggallardoh https://github.com/Ggallardoh gh-60, America/Santiago into DST
|
7
14
|
* Khaled AbuShqear https://github.com/shqear93 gh-57, "12pm"
|
data/LICENSE.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
Copyright (c) 2017-
|
2
|
+
Copyright (c) 2017-2023, John Mettraux, jmettraux+flor@gmail.com
|
3
3
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ The intersection of those two projects is where fugit is born:
|
|
32
32
|
### Projects using fugit
|
33
33
|
|
34
34
|
* [arask](https://github.com/Ebbe/arask) - "Automatic RAils taSKs" uses fugit to parse cron strings
|
35
|
-
* [
|
35
|
+
* [sidekiq-cron](https://github.com/ondrejbartas/sidekiq-cron) - recent versions of Sidekiq-Cron use fugit to parse cron strings
|
36
36
|
* [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler) -
|
37
37
|
* [flor](https://github.com/floraison/flor) - used in the [cron](https://github.com/floraison/flor/blob/master/doc/procedures/cron.md) procedure
|
38
38
|
* [que-scheduler](https://github.com/hlascelles/que-scheduler) - a reliable job scheduler for [que](https://github.com/chanks/que)
|
@@ -89,6 +89,25 @@ Fugit.parse_nat('every day at noon').class # ==> ::Fugit::Cron
|
|
89
89
|
|
90
90
|
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.
|
91
91
|
|
92
|
+
## parse_cronish and do_parse_cronish
|
93
|
+
|
94
|
+
Sometimes you know a cron expression or an "every" natural expression will come in and you want to discard the rest.
|
95
|
+
|
96
|
+
```
|
97
|
+
require 'fugit'
|
98
|
+
|
99
|
+
Fugit.parse_cronish('0 0 1 jan *').class # ==> ::Fugit::Cron
|
100
|
+
Fugit.parse_cronish('every saturday at noon').class # ==> ::Fugit::Cron
|
101
|
+
|
102
|
+
Fugit.parse_cronish('12y12M') # ==> nil
|
103
|
+
```
|
104
|
+
|
105
|
+
`.parse_cronish(s)` will return a `Fugit::Cron` instance or else nil.
|
106
|
+
|
107
|
+
`.do_parse_cronish(s)` will return a `Fugit::Cron` instance or else fail with an `ArgumentError`.
|
108
|
+
|
109
|
+
Introduced in fugit 1.8.0.
|
110
|
+
|
92
111
|
## `Fugit::Cron`
|
93
112
|
|
94
113
|
A class `Fugit::Cron` to parse cron strings and then `#next_time` and `#previous_time` to compute the next or the previous occurrence respectively.
|
@@ -160,7 +179,34 @@ The man page says:
|
|
160
179
|
|
161
180
|
Fugit follows this specification.
|
162
181
|
|
163
|
-
|
182
|
+
Since fugit 1.7.0, by adding `&` right after a day specifier, the `day-of-month OR day-of-week` becomes `day-of-month AND day-of-week`.
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
# standard cron
|
186
|
+
|
187
|
+
p Fugit.parse_cron('0 0 */2 * 1-5').next_time('2022-08-09').to_s
|
188
|
+
# ==> "2022-08-10 00:00:00 +0900"
|
189
|
+
|
190
|
+
# with an &
|
191
|
+
|
192
|
+
p Fugit.parse_cron('0 0 */2 * 1-5&').next_time('2022-08-09').to_s # or
|
193
|
+
p Fugit.parse_cron('0 0 */2& * 1-5').next_time('2022-08-09').to_s
|
194
|
+
p Fugit.parse_cron('0 0 */2& * 1-5&').next_time('2022-08-09').to_s
|
195
|
+
# ==> "2022-08-11 00:00:00 +0900"
|
196
|
+
|
197
|
+
|
198
|
+
# standard cron
|
199
|
+
|
200
|
+
p Fugit.parse_cron('59 6 1-7 * 2').next_time('2020-03-15').to_s
|
201
|
+
# ==> "2020-03-17 06:59:00 +0900"
|
202
|
+
|
203
|
+
# with an &
|
204
|
+
|
205
|
+
p Fugit.parse_cron('59 6 1-7 * 2&').next_time('2020-03-15').to_s
|
206
|
+
p Fugit.parse_cron('59 6 1-7& * 2').next_time('2020-03-15').to_s
|
207
|
+
p Fugit.parse_cron('59 6 1-7& * 2&').next_time('2020-03-15').to_s
|
208
|
+
# ==> "2020-04-07 06:59:00 +0900"
|
209
|
+
```
|
164
210
|
|
165
211
|
### the hash extension
|
166
212
|
|
@@ -372,6 +418,36 @@ Fugit::Nat.parse('every day at 16:15 nada 18:30', multi: true)
|
|
372
418
|
`"Every day at midnight"` is supported, but `"Every monday at midnight"` will be interpreted (as of Fugit <= 1.4.x) as `"Every monday at 00:00"`. Sorry about that.
|
373
419
|
|
374
420
|
|
421
|
+
### 12 AM and PM
|
422
|
+
|
423
|
+
How does fugit react with `"12 am"`, `"12 pm"`, `"12 midnight"`, etc?
|
424
|
+
|
425
|
+
```ruby
|
426
|
+
require 'fugit'
|
427
|
+
|
428
|
+
p Fugit.parse('every day at 12am').original # ==> "0 0 * * *"
|
429
|
+
p Fugit.parse('every day at 12pm').original # ==> "0 12 * * *"
|
430
|
+
|
431
|
+
p Fugit.parse('every day at 12:00am').original # ==> "0 0 * * *"
|
432
|
+
p Fugit.parse('every day at 12:00pm').original # ==> "0 12 * * *"
|
433
|
+
p Fugit.parse('every day at 12:00 am').original # ==> "0 0 * * *"
|
434
|
+
p Fugit.parse('every day at 12:00 pm').original # ==> "0 12 * * *"
|
435
|
+
p Fugit.parse('every day at 12:15am').original # ==> "15 0 * * *"
|
436
|
+
p Fugit.parse('every day at 12:15pm').original # ==> "15 12 * * *"
|
437
|
+
p Fugit.parse('every day at 12:15 am').original # ==> "15 0 * * *"
|
438
|
+
p Fugit.parse('every day at 12:15 pm').original # ==> "15 12 * * *"
|
439
|
+
|
440
|
+
p Fugit.parse('every day at 12 noon').original # ==> "0 12 * * *"
|
441
|
+
p Fugit.parse('every day at 12 midnight').original # ==> "0 24 * * *"
|
442
|
+
p Fugit.parse('every day at 12:00 noon').original # ==> "0 12 * * *"
|
443
|
+
p Fugit.parse('every day at 12:00 midnight').original # ==> "0 24 * * *"
|
444
|
+
p Fugit.parse('every day at 12:15 noon').original # ==> "15 12 * * *"
|
445
|
+
p Fugit.parse('every day at 12:15 midnight').original # ==> "15 24 * * *"
|
446
|
+
|
447
|
+
# as of fugit 1.7.2
|
448
|
+
```
|
449
|
+
|
450
|
+
|
375
451
|
## LICENSE
|
376
452
|
|
377
453
|
MIT, see [LICENSE.txt](LICENSE.txt)
|
data/fugit.gemspec
CHANGED
@@ -32,7 +32,7 @@ Time tools for flor and the floraison project. Cron parsing and occurrence compu
|
|
32
32
|
s.files = Dir[
|
33
33
|
'README.{md,txt}',
|
34
34
|
'CHANGELOG.{md,txt}', 'CREDITS.{md,txt}', 'LICENSE.{md,txt}',
|
35
|
-
'Makefile',
|
35
|
+
#'Makefile',
|
36
36
|
'lib/**/*.rb', #'spec/**/*.rb', 'test/**/*.rb',
|
37
37
|
"#{s.name}.gemspec",
|
38
38
|
]
|
data/lib/fugit/cron.rb
CHANGED
@@ -38,7 +38,7 @@ module Fugit
|
|
38
38
|
return nil unless s.is_a?(String)
|
39
39
|
|
40
40
|
#p s; Raabro.pp(Parser.parse(s, debug: 3), colors: true)
|
41
|
-
h = Parser.parse(s)
|
41
|
+
h = Parser.parse(s.strip)
|
42
42
|
|
43
43
|
return nil unless h
|
44
44
|
|
@@ -167,7 +167,7 @@ module Fugit
|
|
167
167
|
|
168
168
|
def weekday_modulo_match?(nt, mod)
|
169
169
|
|
170
|
-
(nt.rweek
|
170
|
+
(nt.rweek % mod[0]) == (mod[1] % mod[0])
|
171
171
|
end
|
172
172
|
|
173
173
|
def weekday_match?(nt)
|
@@ -199,8 +199,14 @@ module Fugit
|
|
199
199
|
|
200
200
|
def day_match?(nt)
|
201
201
|
|
202
|
-
|
203
|
-
|
202
|
+
if @weekdays && @monthdays
|
203
|
+
|
204
|
+
return weekday_match?(nt) && monthday_match?(nt) \
|
205
|
+
if @day_and
|
206
|
+
#
|
207
|
+
# extension for fugit, gh-78
|
208
|
+
|
209
|
+
return weekday_match?(nt) || monthday_match?(nt)
|
204
210
|
#
|
205
211
|
# From `man 5 crontab`
|
206
212
|
#
|
@@ -212,6 +218,8 @@ module Fugit
|
|
212
218
|
# at 4:30 am on the 1st and 15th of each month, plus every Friday.
|
213
219
|
#
|
214
220
|
# as seen in gh-5 and gh-35
|
221
|
+
end
|
222
|
+
|
215
223
|
|
216
224
|
return false unless weekday_match?(nt)
|
217
225
|
return false unless monthday_match?(nt)
|
@@ -482,6 +490,7 @@ module Fugit
|
|
482
490
|
|
483
491
|
@original = original
|
484
492
|
@cron_s = nil # just to be sure
|
493
|
+
@day_and = h[:&]
|
485
494
|
|
486
495
|
determine_seconds(h[:sec])
|
487
496
|
determine_minutes(h[:min])
|
@@ -500,8 +509,6 @@ module Fugit
|
|
500
509
|
|
501
510
|
sta, edn, sla = r
|
502
511
|
|
503
|
-
sla = nil if sla == 1 # don't get fooled by /1
|
504
|
-
|
505
512
|
edn = max if sla && edn.nil?
|
506
513
|
|
507
514
|
return [ nil ] if sta.nil? && edn.nil? && sla.nil?
|
@@ -516,6 +523,8 @@ module Fugit
|
|
516
523
|
|
517
524
|
def range(min, max, sta, edn, sla)
|
518
525
|
|
526
|
+
return [ nil ] if sta == min && edn == max && sla == 1
|
527
|
+
|
519
528
|
fail ArgumentError.new(
|
520
529
|
'both start and end must be negative in ' +
|
521
530
|
{ min: min, max: max, sta: sta, edn: edn, sla: sla }.inspect
|
@@ -660,7 +669,9 @@ module Fugit
|
|
660
669
|
def s(i); rex(nil, i, /[ \t]+/); end
|
661
670
|
def star(i); str(nil, i, '*'); end
|
662
671
|
def hyphen(i); str(nil, i, '-'); end
|
663
|
-
def comma(i);
|
672
|
+
def comma(i); rex(nil, i, /,([ \t]*,)*/); end
|
673
|
+
def comma?(i); rex(nil, i, /([ \t]*,)*/); end
|
674
|
+
def and?(i); rex(nil, i, /&?/); end
|
664
675
|
|
665
676
|
def slash(i); rex(:slash, i, /\/\d\d?/); end
|
666
677
|
|
@@ -720,12 +731,12 @@ module Fugit
|
|
720
731
|
def list_mon(i); jseq(:mon, i, :mon_elt, :comma); end
|
721
732
|
def list_dow(i); jseq(:dow, i, :dow_elt_, :comma); end
|
722
733
|
|
723
|
-
def lsec_(i); seq(nil, i, :list_sec, :s); end
|
724
|
-
def lmin_(i); seq(nil, i, :list_min, :s); end
|
725
|
-
def lhou_(i); seq(nil, i, :list_hou, :s); end
|
726
|
-
def ldom_(i); seq(nil, i, :list_dom, :s); end
|
727
|
-
def lmon_(i); seq(nil, i, :list_mon, :s); end
|
728
|
-
|
734
|
+
def lsec_(i); seq(nil, i, :comma?, :list_sec, :comma?, :s); end
|
735
|
+
def lmin_(i); seq(nil, i, :comma?, :list_min, :comma?, :s); end
|
736
|
+
def lhou_(i); seq(nil, i, :comma?, :list_hou, :comma?, :s); end
|
737
|
+
def ldom_(i); seq(nil, i, :comma?, :list_dom, :comma?, :and?, :s); end
|
738
|
+
def lmon_(i); seq(nil, i, :comma?, :list_mon, :comma?, :s); end
|
739
|
+
def ldow(i); seq(nil, i, :comma?, :list_dow, :comma?, :and?); end
|
729
740
|
|
730
741
|
def _tz_name(i)
|
731
742
|
rex(nil, i, / +[A-Z][a-zA-Z0-9+\-]+(\/[A-Z][a-zA-Z0-9+\-_]+){0,2}/)
|
@@ -736,10 +747,12 @@ module Fugit
|
|
736
747
|
def _tz(i); alt(:tz, i, :_tz_delta, :_tz_name); end
|
737
748
|
|
738
749
|
def classic_cron(i)
|
739
|
-
seq(:ccron, i,
|
750
|
+
seq(:ccron, i,
|
751
|
+
:lmin_, :lhou_, :ldom_, :lmon_, :ldow, :_tz, '?')
|
740
752
|
end
|
741
753
|
def second_cron(i)
|
742
|
-
seq(:scron, i,
|
754
|
+
seq(:scron, i,
|
755
|
+
:lsec_, :lmin_, :lhou_, :ldom_, :lmon_, :ldow, :_tz, '?')
|
743
756
|
end
|
744
757
|
|
745
758
|
def cron(i)
|
@@ -821,6 +834,7 @@ module Fugit
|
|
821
834
|
.inject({}) { |h, tt|
|
822
835
|
h[tt.name] = tt.name == :tz ? rewrite_tz(tt) : rewrite_entry(tt)
|
823
836
|
h }
|
837
|
+
hcron[:&] = true if t.string.index('&')
|
824
838
|
|
825
839
|
z, tz = hcron[:tz]; return nil if z && ! tz
|
826
840
|
|
data/lib/fugit/duration.rb
CHANGED
@@ -68,8 +68,10 @@ module Fugit
|
|
68
68
|
hou: { a: 'h', r: 'h', i: 'H', s: 3600, I: true, l: 'hour' },
|
69
69
|
min: { a: 'm', r: 'm', i: 'M', s: 60, I: true, l: 'minute' },
|
70
70
|
sec: { a: 's', r: 's', i: 'S', s: 1, I: true, l: 'second' } }.freeze
|
71
|
-
|
72
|
-
|
71
|
+
|
72
|
+
INFLA_KEYS, NON_INFLA_KEYS = KEYS
|
73
|
+
.partition { |k, v| v[:I] }
|
74
|
+
.collect(&:freeze)
|
73
75
|
|
74
76
|
def _to_s(key)
|
75
77
|
|
@@ -240,7 +242,7 @@ module Fugit
|
|
240
242
|
n, m = at[1] / 12, at[1] % 12
|
241
243
|
at[0], at[1] = at[0] + n, m
|
242
244
|
elsif at[1] < 1
|
243
|
-
n, m = -at[1] / 12,
|
245
|
+
n, m = (-at[1]) / 12 + 1, (11+at[1]) % 12 + 1
|
244
246
|
at[0], at[1] = at[0] - n, m
|
245
247
|
end
|
246
248
|
|
@@ -269,7 +271,7 @@ module Fugit
|
|
269
271
|
when Numeric then add_numeric(-a)
|
270
272
|
when Fugit::Duration then add_duration(-a)
|
271
273
|
when String then add_duration(-self.class.parse(a))
|
272
|
-
when ::Time, ::EtOrbi::EoTime then add_to_time(a)
|
274
|
+
when ::Time, ::EtOrbi::EoTime then opposite.add_to_time(a)
|
273
275
|
else fail ArgumentError.new(
|
274
276
|
"cannot subtract #{a.class} instance to a Fugit::Duration")
|
275
277
|
end
|
data/lib/fugit/nat.rb
CHANGED
@@ -15,6 +15,8 @@ module Fugit
|
|
15
15
|
|
16
16
|
return nil unless s.is_a?(String)
|
17
17
|
|
18
|
+
s = s.strip
|
19
|
+
|
18
20
|
#p s; Raabro.pp(Parser.parse(s, debug: 3), colours: true)
|
19
21
|
#(p s; Raabro.pp(Parser.parse(s, debug: 1), colours: true)) rescue nil
|
20
22
|
|
@@ -174,6 +176,7 @@ module Fugit
|
|
174
176
|
#'every week on monday 18:23' => '23 18 * * 1',
|
175
177
|
#
|
176
178
|
# every month on the 1st
|
179
|
+
#
|
177
180
|
def on(i)
|
178
181
|
seq(:on, i, :_on, :on_objects)
|
179
182
|
end
|
@@ -194,12 +197,6 @@ module Fugit
|
|
194
197
|
seq(nil, i, :_in_or_on, '?', :tz)
|
195
198
|
end
|
196
199
|
|
197
|
-
def digital_hour(i)
|
198
|
-
rex(
|
199
|
-
:digital_hour, i,
|
200
|
-
/(2[0-4]|[0-1]?[0-9]):([0-5][0-9])([ \t]*(am|pm))?/i)
|
201
|
-
end
|
202
|
-
|
203
200
|
def ampm(i)
|
204
201
|
rex(:ampm, i, /[ \t]*(am|pm|noon|midday|midnight)/i)
|
205
202
|
end
|
@@ -207,6 +204,13 @@ module Fugit
|
|
207
204
|
rex(:dark, i, /[ \t]*dark/i)
|
208
205
|
end
|
209
206
|
|
207
|
+
def digital_h(i)
|
208
|
+
rex(:digital_h, i, /(2[0-4]|[0-1]?[0-9]):([0-5][0-9])/i)
|
209
|
+
end
|
210
|
+
def digital_hour(i)
|
211
|
+
seq(:digital_hour, i, :digital_h, :ampm, '?')
|
212
|
+
end
|
213
|
+
|
210
214
|
def simple_h(i)
|
211
215
|
rex(:simple_h, i, /#{(0..24).to_a.reverse.join('|')}/)
|
212
216
|
end
|
@@ -449,20 +453,24 @@ module Fugit
|
|
449
453
|
end
|
450
454
|
|
451
455
|
def rewrite_tz(t)
|
456
|
+
|
452
457
|
slot(:tz, t.string)
|
453
458
|
end
|
454
459
|
|
455
460
|
def rewrite_weekday(t)
|
461
|
+
|
456
462
|
Fugit::Cron::Parser::WEEKDS.index(t.string[0, 3].downcase)
|
457
463
|
end
|
458
464
|
|
459
465
|
def rewrite_weekdays(t)
|
466
|
+
|
460
467
|
#Raabro.pp(t, colours: true)
|
461
468
|
slot(:weekday, _rewrite_subs(t, :weekday))
|
462
469
|
end
|
463
470
|
alias rewrite_on_weekdays rewrite_weekdays
|
464
471
|
|
465
472
|
def rewrite_to_weekday(t)
|
473
|
+
|
466
474
|
wd0, wd1 = _rewrite_subs(t, :weekday)
|
467
475
|
#wd1 = 7 if wd1 == 0
|
468
476
|
slot(:weekday, "#{wd0}-#{wd1}")
|
@@ -473,21 +481,35 @@ module Fugit
|
|
473
481
|
slot(:monthday, "#{md0}-#{md1}")
|
474
482
|
end
|
475
483
|
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
484
|
+
# Try to follow https://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_midnight
|
485
|
+
#
|
486
|
+
def adjust_h(h, m, ap)
|
487
|
+
|
488
|
+
if ap == 'midnight' && h == 12
|
489
|
+
24
|
490
|
+
elsif ap == 'pm' && h < 12 # post meridian
|
491
|
+
h + 12
|
492
|
+
elsif ap == 'am' && h == 12 # ante meridian
|
493
|
+
0
|
494
|
+
else
|
495
|
+
h
|
496
|
+
end
|
480
497
|
end
|
481
498
|
|
482
499
|
def rewrite_digital_hour(t)
|
483
|
-
|
484
|
-
h, m =
|
500
|
+
|
501
|
+
h, m = t.sublookup(:digital_h).strinpd.split(':').collect(&:to_i)
|
502
|
+
ap = t.sublookup(:ampm)
|
503
|
+
h, m = adjust_h(h, m, ap && ap.strinpd), m
|
504
|
+
|
485
505
|
slot(:hm, h, m)
|
486
506
|
end
|
487
507
|
|
488
508
|
def rewrite_simple_hour(t)
|
509
|
+
|
489
510
|
h, ap = t.subgather(nil).collect(&:strinpd)
|
490
|
-
h = adjust_h(h, ap)
|
511
|
+
h = adjust_h(h.to_i, 0, ap)
|
512
|
+
|
491
513
|
slot(:hm, h, 0)
|
492
514
|
end
|
493
515
|
|
@@ -499,12 +521,10 @@ module Fugit
|
|
499
521
|
|
500
522
|
h = ht.strinp
|
501
523
|
m = mt ? mt.strinp : 0
|
502
|
-
#p [ 0, '-->', h, m ]
|
503
524
|
h = NHOURS[h]
|
504
525
|
m = NMINUTES[m] || m
|
505
|
-
#p [ 1, '-->', h, m ]
|
506
526
|
|
507
|
-
h = adjust_h(h, apt && apt.strinpd)
|
527
|
+
h = adjust_h(h, m, apt && apt.strinpd)
|
508
528
|
|
509
529
|
slot(:hm, h, m)
|
510
530
|
end
|
data/lib/fugit/parse.rb
CHANGED
@@ -33,6 +33,19 @@ module Fugit
|
|
33
33
|
fail(ArgumentError.new("found no time information in #{s.inspect}"))
|
34
34
|
end
|
35
35
|
|
36
|
+
def parse_cronish(s, opts={})
|
37
|
+
|
38
|
+
r = parse_cron(s) || parse_nat(s, opts)
|
39
|
+
|
40
|
+
r.is_a?(::Fugit::Cron) ? r : nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def do_parse_cronish(s, opts={})
|
44
|
+
|
45
|
+
parse_cronish(s) ||
|
46
|
+
fail(ArgumentError.new("not cron or 'natural' cron string: #{s.inspect}"))
|
47
|
+
end
|
48
|
+
|
36
49
|
def determine_type(s)
|
37
50
|
|
38
51
|
case self.parse(s)
|
data/lib/fugit.rb
CHANGED
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.
|
4
|
+
version: 1.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: raabro
|
@@ -83,7 +83,6 @@ files:
|
|
83
83
|
- CHANGELOG.md
|
84
84
|
- CREDITS.md
|
85
85
|
- LICENSE.txt
|
86
|
-
- Makefile
|
87
86
|
- README.md
|
88
87
|
- fugit.gemspec
|
89
88
|
- lib/fugit.rb
|
@@ -102,7 +101,7 @@ metadata:
|
|
102
101
|
bug_tracker_uri: https://github.com/floraison/fugit/issues
|
103
102
|
homepage_uri: https://github.com/floraison/fugit
|
104
103
|
source_code_uri: https://github.com/floraison/fugit
|
105
|
-
post_install_message:
|
104
|
+
post_install_message:
|
106
105
|
rdoc_options: []
|
107
106
|
require_paths:
|
108
107
|
- lib
|
@@ -117,8 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
116
|
- !ruby/object:Gem::Version
|
118
117
|
version: '0'
|
119
118
|
requirements: []
|
120
|
-
rubygems_version: 3.1.
|
121
|
-
signing_key:
|
119
|
+
rubygems_version: 3.1.6
|
120
|
+
signing_key:
|
122
121
|
specification_version: 4
|
123
122
|
summary: time tools for flor
|
124
123
|
test_files: []
|
data/Makefile
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
|
2
|
-
## gem tasks ##
|
3
|
-
|
4
|
-
NAME = \
|
5
|
-
$(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name")
|
6
|
-
VERSION = \
|
7
|
-
$(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.version")
|
8
|
-
|
9
|
-
count_lines:
|
10
|
-
find lib -name "*.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
|
11
|
-
find spec -name "*_spec.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
|
12
|
-
cl: count_lines
|
13
|
-
|
14
|
-
scan:
|
15
|
-
scan lib/**/*.rb
|
16
|
-
|
17
|
-
gemspec_validate:
|
18
|
-
@echo "---"
|
19
|
-
ruby -e "s = eval(File.read(Dir['*.gemspec'].first)); p s.validate"
|
20
|
-
@echo "---"
|
21
|
-
|
22
|
-
name: gemspec_validate
|
23
|
-
@echo "$(NAME) $(VERSION)"
|
24
|
-
|
25
|
-
cw:
|
26
|
-
find lib -name "*.rb" -exec ruby -cw {} \;
|
27
|
-
|
28
|
-
build: gemspec_validate
|
29
|
-
gem build $(NAME).gemspec
|
30
|
-
mkdir -p pkg
|
31
|
-
mv $(NAME)-$(VERSION).gem pkg/
|
32
|
-
|
33
|
-
push: build
|
34
|
-
gem push --otp "$(OTP)" pkg/$(NAME)-$(VERSION).gem
|
35
|
-
|
36
|
-
spec:
|
37
|
-
bundle exec rspec
|
38
|
-
test: spec
|
39
|
-
|
40
|
-
|
41
|
-
## specific to project ##
|
42
|
-
|
43
|
-
info:
|
44
|
-
uname -a
|
45
|
-
bundle exec ruby -v
|
46
|
-
bundle exec ruby -Ilib -r et-orbi -e "EtOrbi._make_info"
|
47
|
-
|
48
|
-
tzones:
|
49
|
-
bundle exec ruby -r tzinfo -e "TZInfo::Timezone.all.each { |tz| p tz.name }"
|
50
|
-
#tzonesd:
|
51
|
-
# bundle exec ruby -r tzinfo -r tzinfo-data -e "::TZInfo::Timezone.all.each { |tz| p tz.name }"
|
52
|
-
|
53
|
-
|
54
|
-
.PHONY: count_lines scan gemspec_validate name cw build push spec info tzones
|
55
|
-
|