fugit 1.8.0 → 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: fe369cec5c3fb690ead6f7638fcd430db71fd6525070c45aa48a8c7b3c3d4171
4
- data.tar.gz: ce486e692afb9bf796122005314c89185373b07d596684b8c7a3f395bf36d1b4
3
+ metadata.gz: '0099e4aa474e4886e99da33f4b76abd19f259d3a6eb64cd2bfe12f99f6256a23'
4
+ data.tar.gz: 38c3fbe7b620cc6460f1b7b7d3e96298400c82d7dec7ef9d4b543925dff6e74a
5
5
  SHA512:
6
- metadata.gz: 94b9b504e574dbff1f6b0abab21028c97c0303533a8b45747ae6250c6d866c83c7b1999c5cce4680f5015f62946e9ba2f0a2e28af0faf5dc6194c3649b615b97
7
- data.tar.gz: a70bdcd045774d4290cc7d014c62793e28f4a322bf8a3f93d7ee5ce2b2d37744481d32896ce5c88ff89cd3fddfe7ec37bf41c5d3b480dafea45a0d246e1636bd
6
+ metadata.gz: 75e41e393e779e06ec6280e6e2065877b4771fcca8b63307af13f7fe2407fc9a1fef75eca5a690fe9f3cec6b791deaa4c8b23c925326b24753c5ae8197d5a5bd
7
+ data.tar.gz: e9ac1c2b0412a9e2549257b1d73490f4319335c847a6faff212dd8c8a9cbaa52787617491d76648763efbd24caffc39a91e08f06910970905dc810ef9fec36cc
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
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
+
11
+ ## fugit 1.8.1 released 2023-01-20
12
+
13
+ * Fix for month subtraction, gh-84, @mreinsch
14
+ * Fix duration - time, gh-85, @mreinsch
15
+
16
+
5
17
  ## fugit 1.8.0 released 2022-12-06
6
18
 
7
19
  * Introduce Fugit.parse_cronish and .do_parse_cronish, gh-70
data/CREDITS.md CHANGED
@@ -1,6 +1,9 @@
1
1
 
2
2
  # fugit credits
3
3
 
4
+ * Marcos Belluci, https://github.com/delbetu, gh-88 , 1st and last nat
5
+ * Michael Reinsch, https://github.com/mreinsch, gh-84 and gh-85
6
+ * Marc Anguera, https://github.com/markets, gh-70 and Sidekiq-Cron
4
7
  * ski-nine, https://github.com/ski-nine, gh-81
5
8
  * Joseph Halter, https://github.com/JosephHalter, gh-79
6
9
  * James Healy, https://github.com/yob, gh-76
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2017-2022, John Mettraux, jmettraux+flor@gmail.com
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
@@ -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
@@ -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
- INFLA_KEYS, NON_INFLA_KEYS =
72
- KEYS.partition { |k, v| v[:I] }.freeze
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, -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
@@ -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.0'
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.0
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: 2022-12-06 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