fugit 1.8.1 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1839fa07acc6287be95f8076c19afa2c9d6c9b5500ac1b03febab61959b5057
4
- data.tar.gz: 839ff5c0f85ccd51625febfdbfedd017e46962d288cf313307b706830dc838c9
3
+ metadata.gz: '0099e4aa474e4886e99da33f4b76abd19f259d3a6eb64cd2bfe12f99f6256a23'
4
+ data.tar.gz: 38c3fbe7b620cc6460f1b7b7d3e96298400c82d7dec7ef9d4b543925dff6e74a
5
5
  SHA512:
6
- metadata.gz: 5336bf251441fa3f7372d48aec2196cf86831b24c64110955f2ccf2df2e6e1ec84a68b318b53be8282f87794f40c09778bddd47abec3f65fe1469544a758fabb
7
- data.tar.gz: 0fdd70455097838c21c3f03c9dca20889b4aba07f67d790136e40be2d8686b0a6ad8a594fff1fe28e7cd4d322ad66a8a31aa71750cd435c7601345487ae89bdb
6
+ metadata.gz: 75e41e393e779e06ec6280e6e2065877b4771fcca8b63307af13f7fe2407fc9a1fef75eca5a690fe9f3cec6b791deaa4c8b23c925326b24753c5ae8197d5a5bd
7
+ data.tar.gz: e9ac1c2b0412a9e2549257b1d73490f4319335c847a6faff212dd8c8a9cbaa52787617491d76648763efbd24caffc39a91e08f06910970905dc810ef9fec36cc
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## fugit 1.9.0 released 2023-10-24
6
+
7
+ * Let nat parse "last", gh-88
8
+ * Change that I am not sure about, gh-86
9
+
10
+
5
11
  ## fugit 1.8.1 released 2023-01-20
6
12
 
7
13
  * Fix for month subtraction, gh-84, @mreinsch
data/CREDITS.md CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  # fugit credits
3
3
 
4
+ * Marcos Belluci, https://github.com/delbetu, gh-88 , 1st and last nat
4
5
  * Michael Reinsch, https://github.com/mreinsch, gh-84 and gh-85
5
6
  * Marc Anguera, https://github.com/markets, gh-70 and Sidekiq-Cron
6
7
  * ski-nine, https://github.com/ski-nine, gh-81
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
 
4
4
  [![tests](https://github.com/floraison/fugit/workflows/test/badge.svg)](https://github.com/floraison/fugit/actions)
5
5
  [![Gem Version](https://badge.fury.io/rb/fugit.svg)](http://badge.fury.io/rb/fugit)
6
- [![Join the chat at https://gitter.im/floraison/fugit](https://badges.gitter.im/floraison/fugit.svg)](https://gitter.im/floraison/fugit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
7
6
 
8
7
  Time tools for [flor](https://github.com/floraison/flor) and the floraison group.
9
8
 
data/lib/fugit/cron.rb CHANGED
@@ -40,8 +40,6 @@ module Fugit
40
40
  #p s; Raabro.pp(Parser.parse(s, debug: 3), colors: true)
41
41
  h = Parser.parse(s.strip)
42
42
 
43
- return nil unless h
44
-
45
43
  self.allocate.send(:init, s, h)
46
44
  end
47
45
 
@@ -488,18 +486,22 @@ module Fugit
488
486
 
489
487
  def init(original, h)
490
488
 
489
+ return nil unless h
490
+
491
491
  @original = original
492
492
  @cron_s = nil # just to be sure
493
493
  @day_and = h[:&]
494
494
 
495
- determine_seconds(h[:sec])
496
- determine_minutes(h[:min])
497
- determine_hours(h[:hou])
498
- determine_monthdays(h[:dom])
499
- determine_months(h[:mon])
500
- determine_weekdays(h[:dow])
501
- determine_timezone(h[:tz])
495
+ valid =
496
+ determine_seconds(h[:sec]) &&
497
+ determine_minutes(h[:min]) &&
498
+ determine_hours(h[:hou]) &&
499
+ determine_monthdays(h[:dom]) &&
500
+ determine_months(h[:mon]) &&
501
+ determine_weekdays(h[:dow]) &&
502
+ determine_timezone(h[:tz])
502
503
 
504
+ return nil unless valid
503
505
  return nil unless compact_month_days
504
506
 
505
507
  self
@@ -509,10 +511,12 @@ module Fugit
509
511
 
510
512
  sta, edn, sla = r
511
513
 
514
+ return false if sla && sla > max
515
+
512
516
  edn = max if sla && edn.nil?
513
517
 
514
- return [ nil ] if sta.nil? && edn.nil? && sla.nil?
515
- return [ sta ] if sta && edn.nil?
518
+ return nil if sta.nil? && edn.nil? && sla.nil?
519
+ return sta if sta && edn.nil?
516
520
 
517
521
  sla = 1 if sla == nil
518
522
  sta = min if sta == nil
@@ -563,42 +567,41 @@ module Fugit
563
567
  .uniq
564
568
  end
565
569
 
566
- def compact(key)
570
+ def do_determine(key, arr, min, max)
567
571
 
568
- arr = instance_variable_get(key)
572
+ null = false
569
573
 
570
- return instance_variable_set(key, nil) if arr.include?(nil)
571
- # reductio ad astrum
574
+ r = arr
575
+ .collect { |v|
576
+ expand(min, max, v) }
577
+ .flatten(1)
578
+ .collect { |e|
579
+ return false if e == false
580
+ null = null || e == nil
581
+ (key == :hours && e == 24) ? 0 : e }
572
582
 
573
- arr.uniq!
574
- arr.sort!
583
+ return nil if null
584
+ r.uniq.sort
575
585
  end
576
586
 
577
587
  def determine_seconds(arr)
578
- @seconds = (arr || [ 0 ]).inject([]) { |a, s| a.concat(expand(0, 59, s)) }
579
- compact(:@seconds)
588
+ (@seconds = do_determine(:seconds, arr || [ 0 ], 0, 59)) != false
580
589
  end
581
590
 
582
591
  def determine_minutes(arr)
583
- @minutes = arr.inject([]) { |a, m| a.concat(expand(0, 59, m)) }
584
- compact(:@minutes)
592
+ (@minutes = do_determine(:minutes, arr, 0, 59)) != false
585
593
  end
586
594
 
587
595
  def determine_hours(arr)
588
- @hours = arr
589
- .inject([]) { |a, h| a.concat(expand(0, 23, h)) }
590
- .collect { |h| h == 24 ? 0 : h }
591
- compact(:@hours)
596
+ (@hours = do_determine(:hours, arr, 0, 23)) != false
592
597
  end
593
598
 
594
599
  def determine_monthdays(arr)
595
- @monthdays = arr.inject([]) { |a, d| a.concat(expand(1, 31, d)) }
596
- compact(:@monthdays)
600
+ (@monthdays = do_determine(:monthdays, arr, 1, 31)) != false
597
601
  end
598
602
 
599
603
  def determine_months(arr)
600
- @months = arr.inject([]) { |a, m| a.concat(expand(1, 12, m)) }
601
- compact(:@months)
604
+ (@months = do_determine(:months, arr, 1, 12)) != false
602
605
  end
603
606
 
604
607
  def determine_weekdays(arr)
@@ -624,11 +627,15 @@ module Fugit
624
627
  @weekdays.uniq!
625
628
  @weekdays.sort!
626
629
  @weekdays = nil if @weekdays.empty?
630
+
631
+ true
627
632
  end
628
633
 
629
634
  def determine_timezone(z)
630
635
 
631
636
  @zone, @timezone = z
637
+
638
+ true
632
639
  end
633
640
 
634
641
  def weekdays_to_cron_s
data/lib/fugit/nat.rb CHANGED
@@ -642,9 +642,9 @@ module Fugit
642
642
  fail(ArgumentError.new(
643
643
  "multiple crons in #{opts[:_s].inspect} - #{@slots.inspect}"))
644
644
  elsif multi == true
645
- hms.collect { |hm| parse_cron(hm) }
645
+ hms.collect { |hm| parse_cron(hm, opts) }
646
646
  else
647
- parse_cron(hms.first)
647
+ parse_cron(hms.first, opts)
648
648
  end
649
649
  end
650
650
 
@@ -678,7 +678,7 @@ module Fugit
678
678
  .to_a
679
679
  end
680
680
 
681
- def parse_cron(hm)
681
+ def parse_cron(hm, opts)
682
682
 
683
683
  a = [
684
684
  slot(:second, '0'),
@@ -691,11 +691,39 @@ module Fugit
691
691
  a << tz.data0 if tz
692
692
  a.shift if a.first == [ '0' ]
693
693
 
694
+ letters_last = lambda { |x| x.is_a?(Numeric) ? x : 999_999 }
695
+
694
696
  s = a
695
- .collect { |e| e.uniq.sort.collect(&:to_s).join(',') }
697
+ .collect { |e|
698
+ e.uniq.sort_by(&letters_last).collect(&:to_s).join(',') }
696
699
  .join(' ')
697
700
 
698
- Fugit::Cron.parse(s)
701
+ c = Fugit::Cron.parse(s)
702
+
703
+ if opts[:strict]
704
+ restrict(a, c)
705
+ else
706
+ c
707
+ end
708
+ end
709
+
710
+ # Return nil if the cron is "not strict"
711
+ #
712
+ # For example, "0 0/17 * * *" (gh-86) is a perfectly valid
713
+ # cron string, but makes not much sense when derived via `.parse_nat`
714
+ # from "every 17 hours".
715
+ #
716
+ # It happens here because it's nat being strict, not cron.
717
+ #
718
+ def restrict(a, cron)
719
+
720
+ if m = ((a[1] && a[1][0]) || '').match(/^(\d+|\*)\/(\d+)$/)
721
+ #p m
722
+ sla = m[1].to_i
723
+ return nil unless [ 1, 2, 3, 4, 5, 6, 8, 12 ].include?(sla)
724
+ end
725
+
726
+ cron
699
727
  end
700
728
 
701
729
  def slot(key, default)
data/lib/fugit.rb CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Fugit
5
5
 
6
- VERSION = '1.8.1'
6
+ VERSION = '1.9.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.8.1
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-20 00:00:00.000000000 Z
11
+ date: 2023-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: raabro
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubygems_version: 3.1.6
119
+ rubygems_version: 3.2.33
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: time tools for flor