lib/fugit/cron.rb in fugit-1.3.0 vs lib/fugit/cron.rb in fugit-1.3.1

- old
+ new

@@ -473,15 +473,51 @@ return [ sta ] if sta && edn.nil? sla = 1 if sla == nil sta = min if sta == nil edn = max if edn == nil - sta, edn = edn, sta if sta > edn - (sta..edn).step(sla).to_a + range(min, max, sta, edn, sla) end + def range(min, max, sta, edn, sla) + + fail ArgumentError.new( + 'both start and end must be negative in ' + + { min: min, max: max, sta: sta, edn: edn, sla: sla }.inspect + ) if (sta < 0 && edn > 0) || (edn < 0 && sta > 0) + +#p({ min: min, max: max, sta: sta, edn: edn, sla: sla }) + a = [] + + omin, omax = min, max + min, max = -max, -1 if sta < 0 +#p({ min: min, max: max }) + + cur = sta + + loop do + +#p({ cur: cur }) + a << cur + break if cur == edn + + cur += 1 + cur = min if cur > max +#p cur + + fail RuntimeError.new( + "too many loops for " + + { min: omin, max: omax, sta: sta, edn: edn, sla: sla }.inspect + + " #range, breaking, " + + "please fill an issue at https://git.io/fjJC9" + ) if a.length > omax + end + + a.each_with_index.select { |e, i| i % sla == 0 }.collect(&:first) + end + def compact(key) arr = instance_variable_get(key) return instance_variable_set(key, nil) if arr.include?(nil) @@ -527,19 +563,21 @@ @weekdays << [ a, ha || mo ] elsif sl ((a || 0)..(z || (a ? a : 6))).step(sl < 1 ? 1 : sl) .each { |i| @weekdays << [ i ] } elsif z - (a..z).each { |i| @weekdays << [ i ] } + z = z + 7 if a > z + (a..z).each { |i| @weekdays << [ (i > 6) ? i - 7 : i ] } elsif a @weekdays << [ a ] #else end end @weekdays.each { |wd| wd[0] = 0 if wd[0] == 7 } # turn sun7 into sun0 @weekdays.uniq! + @weekdays.sort! @weekdays = nil if @weekdays.empty? end def determine_timezone(z) @@ -683,10 +721,12 @@ mo = mot ? rewrite_mod(k, mot) : nil a = at ? rewrite_bound(k, at) : nil z = zt ? rewrite_bound(k, zt) : nil - a, z = z, a if a && z && a > z + + #a, z = z, a if a && z && a > z + # handled downstream since gh-27 [ a, z, sl, ha, mo ] end def rewrite_entry(t)