fugit 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57336fd846b610ad0c361564a8025f3ccb752025
4
- data.tar.gz: 4effff19a32313a7eefad03b6ba1eebe1d056e62
3
+ metadata.gz: b6c020a2dc2dea8ee73eae196c502e1353839f84
4
+ data.tar.gz: d4d43e932e0e4de4d07d402db975bf2a642df687
5
5
  SHA512:
6
- metadata.gz: 429bc3055890b87c7a1cb78da8d713844f73de3bc162295ce7e0688179800caec9c5bb96b792276b1bf71ee40de1cee50070553ccbeb98e6150abe7b168b3f9c
7
- data.tar.gz: 95fa1fc74e5ebdef176edd772d7978f8c845ecd9d9e465450ae3d61d6d7cebca89bca8cb43cc1e1e4986ff22a392fb08c58525d4ed5c5a9cd31ee8539efd4738
6
+ metadata.gz: 7c7f5319195ca991c848826b336023f429fc21ad033b26d67b7011872b91d1e9f8fb639b2618eda9dd1e199d7e473599e356924f302bb5cbaba20817aa6ab050
7
+ data.tar.gz: 4358df79feebbdb50509b78735fad8210d5c3d001d6a0b3d5a85aa375be08605816ea87510abc8188b5e42d091cd4d47af91a18061d956dc10a115fd9397c7eb
@@ -2,6 +2,14 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## fugit 1.3.1 released 2019-07-27
6
+
7
+ * Fix nat parsing for 'every day at 18:00 and 18:15', gh-29
8
+ * and for 'every day at 18:00, 18:15, 20:00, and 20:15', gh-29
9
+ * Ensure multi: :fail doesn't force into multi, gh-28
10
+ * Fix nat parsing for 'every Fri-Sun at 18:00', gh-27
11
+
12
+
5
13
  ## fugit 1.3.0 released 2019-07-21
6
14
 
7
15
  * Introduce Fugit.parse_nat('every day at 18:00 and 19:15', multi: true)
data/CREDITS.md CHANGED
@@ -1,7 +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
+ * Shai Coleman https://github.com/shaicoleman parse_nat enhancements, gh-24, gh-25, and gh-28
5
5
  * Jan Stevens https://github.com/JanStevens Fugit.parse('every 15 minutes') gh-22
6
6
  * Fabio Pitino https://github.com/hspazio nil on February 30 gh-21
7
7
  * Cristian Oneț https://github.com/conet #previous_time vs 1/-1 endless loop gh-15
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Fugit
3
3
 
4
- VERSION = '1.3.0'
4
+ VERSION = '1.3.1'
5
5
  end
6
6
 
7
7
  require 'time'
@@ -475,9 +475,45 @@ module Fugit
475
475
  sla = 1 if sla == nil
476
476
  sta = min if sta == nil
477
477
  edn = max if edn == nil
478
- sta, edn = edn, sta if sta > edn
479
478
 
480
- (sta..edn).step(sla).to_a
479
+ range(min, max, sta, edn, sla)
480
+ end
481
+
482
+ def range(min, max, sta, edn, sla)
483
+
484
+ fail ArgumentError.new(
485
+ 'both start and end must be negative in ' +
486
+ { min: min, max: max, sta: sta, edn: edn, sla: sla }.inspect
487
+ ) if (sta < 0 && edn > 0) || (edn < 0 && sta > 0)
488
+
489
+ #p({ min: min, max: max, sta: sta, edn: edn, sla: sla })
490
+ a = []
491
+
492
+ omin, omax = min, max
493
+ min, max = -max, -1 if sta < 0
494
+ #p({ min: min, max: max })
495
+
496
+ cur = sta
497
+
498
+ loop do
499
+
500
+ #p({ cur: cur })
501
+ a << cur
502
+ break if cur == edn
503
+
504
+ cur += 1
505
+ cur = min if cur > max
506
+ #p cur
507
+
508
+ fail RuntimeError.new(
509
+ "too many loops for " +
510
+ { min: omin, max: omax, sta: sta, edn: edn, sla: sla }.inspect +
511
+ " #range, breaking, " +
512
+ "please fill an issue at https://git.io/fjJC9"
513
+ ) if a.length > omax
514
+ end
515
+
516
+ a.each_with_index.select { |e, i| i % sla == 0 }.collect(&:first)
481
517
  end
482
518
 
483
519
  def compact(key)
@@ -529,7 +565,8 @@ module Fugit
529
565
  ((a || 0)..(z || (a ? a : 6))).step(sl < 1 ? 1 : sl)
530
566
  .each { |i| @weekdays << [ i ] }
531
567
  elsif z
532
- (a..z).each { |i| @weekdays << [ i ] }
568
+ z = z + 7 if a > z
569
+ (a..z).each { |i| @weekdays << [ (i > 6) ? i - 7 : i ] }
533
570
  elsif a
534
571
  @weekdays << [ a ]
535
572
  #else
@@ -538,6 +575,7 @@ module Fugit
538
575
 
539
576
  @weekdays.each { |wd| wd[0] = 0 if wd[0] == 7 } # turn sun7 into sun0
540
577
  @weekdays.uniq!
578
+ @weekdays.sort!
541
579
  @weekdays = nil if @weekdays.empty?
542
580
  end
543
581
 
@@ -685,7 +723,9 @@ module Fugit
685
723
 
686
724
  a = at ? rewrite_bound(k, at) : nil
687
725
  z = zt ? rewrite_bound(k, zt) : nil
688
- a, z = z, a if a && z && a > z
726
+
727
+ #a, z = z, a if a && z && a > z
728
+ # handled downstream since gh-27
689
729
 
690
730
  [ a, z, sl, ha, mo ]
691
731
  end
@@ -37,13 +37,16 @@ module Fugit
37
37
 
38
38
  def parse_crons(s, a, opts)
39
39
 
40
- dhs, aa =
41
- a.partition { |e| e[0] == :digital_hour }
42
- dms =
43
- dhs.collect { |dh| dh[1][1] }.uniq
40
+ dhs, aa = a
41
+ .partition { |e| e[0] == :digital_hour }
42
+ ms = dhs
43
+ .inject({}) { |h, dh| (h[dh[1][0]] ||= []) << dh[1][1]; h }
44
+ .values
45
+ .uniq
44
46
 
45
47
  crons =
46
- if dhs.empty? || dms.size == 1
48
+ #if ms.size <= 1 || hs.size <= 1
49
+ if ms.size <= 1
47
50
  [ parse_cron(a, opts) ]
48
51
  else
49
52
  dhs.collect { |dh| parse_cron([ dh ] + aa, opts) }
@@ -54,7 +57,7 @@ module Fugit
54
57
  "(#{crons.collect(&:original).join(' | ')})"
55
58
  ) if opts[:multi] == :fail && crons.size > 1
56
59
 
57
- if opts[:multi]
60
+ if opts[:multi] == true || (opts[:multi] && opts[:multi] != :fail)
58
61
  crons
59
62
  else
60
63
  crons.first
@@ -84,9 +87,13 @@ module Fugit
84
87
  process_duration(h, *val[0].to_h.first)
85
88
  end
86
89
  end
90
+
87
91
  h[:min] ||= [ 0 ]
88
92
  h[:min].uniq!
89
- h[:hou].sort! if h[:hou]
93
+
94
+ h[:hou].uniq!;
95
+ h[:hou].sort!
96
+
90
97
  h[:dow].sort! if h[:dow]
91
98
 
92
99
  a = hkeys
@@ -95,9 +102,9 @@ module Fugit
95
102
  (v && v.any?) ? v.collect(&:to_s).join(',') : '*' }
96
103
  a.insert(0, h[:sec]) if h[:sec]
97
104
  a << h[:tz].first if h[:tz]
105
+
98
106
  s = a.join(' ')
99
107
 
100
- #p s
101
108
  Fugit::Cron.parse(s)
102
109
  end
103
110
 
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.3.0
4
+ version: 1.3.1
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-07-21 00:00:00.000000000 Z
11
+ date: 2019-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: raabro