fugit 1.7.1 → 1.8.0

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
  SHA256:
3
- metadata.gz: 318e360c503855580a65262f188ae07d02a17c1e833aeb5d8d21e25a67a9805c
4
- data.tar.gz: 54b9eaeba60e6c1a64db0ca2b5e86ed09e74d8c4afeb32677314946f8b1d5211
3
+ metadata.gz: fe369cec5c3fb690ead6f7638fcd430db71fd6525070c45aa48a8c7b3c3d4171
4
+ data.tar.gz: ce486e692afb9bf796122005314c89185373b07d596684b8c7a3f395bf36d1b4
5
5
  SHA512:
6
- metadata.gz: c2813ab3974e9dcc7b3b6552bc8a5855617ac40b26190f84a3cbd413108d4b2ebc6a8c9418389a873844161289f60d48bece8fc10ca25295414e2e04c1da1474
7
- data.tar.gz: 6e8587a3894c801bc220f967e3f5b0fed6e1bdea0bc606841fe188f890c8a0f6756f4b5357fd4cd887ff7d9bfd0a6bde68a1405ff369f7b4d41b8ec3e14c1c4b
6
+ metadata.gz: 94b9b504e574dbff1f6b0abab21028c97c0303533a8b45747ae6250c6d866c83c7b1999c5cce4680f5015f62946e9ba2f0a2e28af0faf5dc6194c3649b615b97
7
+ data.tar.gz: a70bdcd045774d4290cc7d014c62793e28f4a322bf8a3f93d7ee5ce2b2d37744481d32896ce5c88ff89cd3fddfe7ec37bf41c5d3b480dafea45a0d246e1636bd
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## fugit 1.8.0 released 2022-12-06
6
+
7
+ * Introduce Fugit.parse_cronish and .do_parse_cronish, gh-70
8
+
9
+
10
+ ## fugit 1.7.2 released 2022-11-03
11
+
12
+ * Fix 'every day at 12:15 am', gh-81
13
+ * Fix 'every day at 5:00pm', gh-81
14
+
15
+
5
16
  ## fugit 1.7.1 released 2022-09-21
6
17
 
7
18
  * Change behaviour for "0 0/5 * * *", gh-79
data/CREDITS.md CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  # fugit credits
3
3
 
4
+ * ski-nine, https://github.com/ski-nine, gh-81
4
5
  * Joseph Halter, https://github.com/JosephHalter, gh-79
5
6
  * James Healy, https://github.com/yob, gh-76
6
7
  * John Bachir, https://github.com/jjb, gh-74
data/README.md CHANGED
@@ -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.
@@ -399,6 +418,36 @@ Fugit::Nat.parse('every day at 16:15 nada 18:30', multi: true)
399
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.
400
419
 
401
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
+
402
451
  ## LICENSE
403
452
 
404
453
  MIT, see [LICENSE.txt](LICENSE.txt)
data/lib/fugit/nat.rb CHANGED
@@ -176,6 +176,7 @@ module Fugit
176
176
  #'every week on monday 18:23' => '23 18 * * 1',
177
177
  #
178
178
  # every month on the 1st
179
+ #
179
180
  def on(i)
180
181
  seq(:on, i, :_on, :on_objects)
181
182
  end
@@ -196,12 +197,6 @@ module Fugit
196
197
  seq(nil, i, :_in_or_on, '?', :tz)
197
198
  end
198
199
 
199
- def digital_hour(i)
200
- rex(
201
- :digital_hour, i,
202
- /(2[0-4]|[0-1]?[0-9]):([0-5][0-9])([ \t]*(am|pm))?/i)
203
- end
204
-
205
200
  def ampm(i)
206
201
  rex(:ampm, i, /[ \t]*(am|pm|noon|midday|midnight)/i)
207
202
  end
@@ -209,6 +204,13 @@ module Fugit
209
204
  rex(:dark, i, /[ \t]*dark/i)
210
205
  end
211
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
+
212
214
  def simple_h(i)
213
215
  rex(:simple_h, i, /#{(0..24).to_a.reverse.join('|')}/)
214
216
  end
@@ -451,20 +453,24 @@ module Fugit
451
453
  end
452
454
 
453
455
  def rewrite_tz(t)
456
+
454
457
  slot(:tz, t.string)
455
458
  end
456
459
 
457
460
  def rewrite_weekday(t)
461
+
458
462
  Fugit::Cron::Parser::WEEKDS.index(t.string[0, 3].downcase)
459
463
  end
460
464
 
461
465
  def rewrite_weekdays(t)
466
+
462
467
  #Raabro.pp(t, colours: true)
463
468
  slot(:weekday, _rewrite_subs(t, :weekday))
464
469
  end
465
470
  alias rewrite_on_weekdays rewrite_weekdays
466
471
 
467
472
  def rewrite_to_weekday(t)
473
+
468
474
  wd0, wd1 = _rewrite_subs(t, :weekday)
469
475
  #wd1 = 7 if wd1 == 0
470
476
  slot(:weekday, "#{wd0}-#{wd1}")
@@ -475,21 +481,35 @@ module Fugit
475
481
  slot(:monthday, "#{md0}-#{md1}")
476
482
  end
477
483
 
478
- def adjust_h(h, ap)
479
- h = h.to_i
480
- ap = ap || ''
481
- (h < 12 && ap == 'pm' || ap == 'midnight') ? h + 12 : h
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
482
497
  end
483
498
 
484
499
  def rewrite_digital_hour(t)
485
- h, m, ap = t.strinpd.split(/[: \t]+/)
486
- h, m = adjust_h(h, ap), m.to_i
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
+
487
505
  slot(:hm, h, m)
488
506
  end
489
507
 
490
508
  def rewrite_simple_hour(t)
509
+
491
510
  h, ap = t.subgather(nil).collect(&:strinpd)
492
- h = adjust_h(h, ap)
511
+ h = adjust_h(h.to_i, 0, ap)
512
+
493
513
  slot(:hm, h, 0)
494
514
  end
495
515
 
@@ -501,12 +521,10 @@ module Fugit
501
521
 
502
522
  h = ht.strinp
503
523
  m = mt ? mt.strinp : 0
504
- #p [ 0, '-->', h, m ]
505
524
  h = NHOURS[h]
506
525
  m = NMINUTES[m] || m
507
- #p [ 1, '-->', h, m ]
508
526
 
509
- h = adjust_h(h, apt && apt.strinpd)
527
+ h = adjust_h(h, m, apt && apt.strinpd)
510
528
 
511
529
  slot(:hm, h, m)
512
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
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Fugit
5
5
 
6
- VERSION = '1.7.1'
6
+ VERSION = '1.8.0'
7
7
  end
8
8
 
9
9
  require 'time'
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.7.1
4
+ version: 1.8.0
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: 2022-09-21 00:00:00.000000000 Z
11
+ date: 2022-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: raabro
@@ -101,7 +101,7 @@ metadata:
101
101
  bug_tracker_uri: https://github.com/floraison/fugit/issues
102
102
  homepage_uri: https://github.com/floraison/fugit
103
103
  source_code_uri: https://github.com/floraison/fugit
104
- post_install_message:
104
+ post_install_message:
105
105
  rdoc_options: []
106
106
  require_paths:
107
107
  - lib
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  requirements: []
119
119
  rubygems_version: 3.1.6
120
- signing_key:
120
+ signing_key:
121
121
  specification_version: 4
122
122
  summary: time tools for flor
123
123
  test_files: []