lib/fugit/cron.rb in fugit-1.3.9 vs lib/fugit/cron.rb in fugit-1.4.0

- old
+ new

@@ -1,5 +1,6 @@ +# frozen_string_literal: true module Fugit class Cron @@ -10,13 +11,13 @@ '@monthly' => '0 0 1 * *', '@weekly' => '0 0 * * 0', '@daily' => '0 0 * * *', '@midnight' => '0 0 * * *', '@noon' => '0 12 * * *', - '@hourly' => '0 * * * *' } + '@hourly' => '0 * * * *' }.freeze MAXDAYS = [ - nil, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ] + nil, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ].freeze attr_reader( :original, :zone) attr_reader( :seconds, :minutes, :hours, :monthdays, :months, :weekdays, :timezone) @@ -334,11 +335,11 @@ SLOTS = [ [ :seconds, 1, 60 ], [ :minutes, 60, 60 ], [ :hours, 3600, 24 ], - [ :days, 24 * 3600, 365 ] ] + [ :days, 24 * 3600, 365 ] ].freeze def rough_frequency slots = SLOTS .collect { |k, v0, v1| @@ -493,11 +494,11 @@ return [ nil ] if sta.nil? && edn.nil? && sla.nil? return [ sta ] if sta && edn.nil? sla = 1 if sla == nil sta = min if sta == nil - edn = max if edn == nil + edn = max if edn == nil || edn < 0 && sta > 0 range(min, max, sta, edn, sla) end def range(min, max, sta, edn, sla) @@ -505,16 +506,14 @@ 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 @@ -610,15 +609,23 @@ @zone, @timezone = z end module Parser include Raabro - WEEKDAYS = %w[ sunday monday tuesday wednesday thursday friday saturday ] - WEEKDS = WEEKDAYS.collect { |d| d[0, 3] } + WEEKDAYS = + %w[ sunday monday tuesday wednesday thursday friday saturday ].freeze - MONTHS = %w[ - jan feb mar apr may jun jul aug sep oct nov dec ] + WEEKDS = + WEEKDAYS.collect { |d| d[0, 3] }.freeze + DOW_REX = + /([0-7]|#{WEEKDS.join('|')})/i.freeze + MONTHS = + %w[ - jan feb mar apr may jun jul aug sep oct nov dec ].freeze + MONTH_REX = + /(1[0-2]|0?[1-9]|#{MONTHS[1..-1].join('|')})/i.freeze + # piece parsers bottom to top def s(i); rex(nil, i, /[ \t]+/); end def star(i); str(nil, i, '*'); end def hyphen(i); str(nil, i, '-'); end @@ -627,11 +634,11 @@ def slash(i); rex(:slash, i, /\/\d\d?/); end def mos(i); rex(:mos, i, /[0-5]?\d/); end # min or sec def hou(i); rex(:hou, i, /(2[0-4]|[01]?[0-9])/); end def dom(i); rex(:dom, i, /(-?(3[01]|[12][0-9]|0?[1-9])|last|l)/i); end - def mon(i); rex(:mon, i, /(1[0-2]|0?[1-9]|#{MONTHS[1..-1].join('|')})/i); end - def dow(i); rex(:dow, i, /([0-7]|#{WEEKDS.join('|')})/i); end + def mon(i); rex(:mon, i, MONTH_REX); end + def dow(i); rex(:dow, i, DOW_REX); end def dow_hash(i); rex(:hash, i, /#(-?[1-5]|last|l)/i); end def _mos(i); seq(nil, i, :hyphen, :mos); end def _hou(i); seq(nil, i, :hyphen, :hou); end