lib/fugit/cron.rb in fugit-1.6.0 vs lib/fugit/cron.rb in fugit-1.7.0

- old
+ new

@@ -165,11 +165,11 @@ end end def weekday_modulo_match?(nt, mod) - (nt.rweek + mod[1]) % mod[0] == 0 + (nt.rweek % mod[0]) == (mod[1] % mod[0]) end def weekday_match?(nt) return true if @weekdays.nil? @@ -197,12 +197,18 @@ .include?(nt.day) end def day_match?(nt) - return weekday_match?(nt) || monthday_match?(nt) \ - if @weekdays && @monthdays + if @weekdays && @monthdays + + return weekday_match?(nt) && monthday_match?(nt) \ + if @day_and + # + # extension for fugit, gh-78 + + return weekday_match?(nt) || monthday_match?(nt) # # From `man 5 crontab` # # Note: The day of a command's execution can be specified # by two fields -- day of month, and day of week. @@ -210,11 +216,13 @@ # run when either field matches the current time. # For example, ``30 4 1,15 * 5'' would cause a command to be run # at 4:30 am on the 1st and 15th of each month, plus every Friday. # # as seen in gh-5 and gh-35 + end + return false unless weekday_match?(nt) return false unless monthday_match?(nt) true end @@ -480,10 +488,11 @@ def init(original, h) @original = original @cron_s = nil # just to be sure + @day_and = h[:&] determine_seconds(h[:sec]) determine_minutes(h[:min]) determine_hours(h[:hou]) determine_monthdays(h[:dom]) @@ -658,11 +667,13 @@ # 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 - def comma(i); str(nil, i, ','); end + def comma(i); rex(nil, i, /,([ \t]*,)*/); end + def comma?(i); rex(nil, i, /([ \t]*,)*/); end + def and?(i); rex(nil, i, /&?/); end 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 @@ -718,30 +729,32 @@ def list_hou(i); jseq(:hou, i, :hou_elt, :comma); end def list_dom(i); jseq(:dom, i, :dom_elt, :comma); end def list_mon(i); jseq(:mon, i, :mon_elt, :comma); end def list_dow(i); jseq(:dow, i, :dow_elt_, :comma); end - def lsec_(i); seq(nil, i, :list_sec, :s); end - def lmin_(i); seq(nil, i, :list_min, :s); end - def lhou_(i); seq(nil, i, :list_hou, :s); end - def ldom_(i); seq(nil, i, :list_dom, :s); end - def lmon_(i); seq(nil, i, :list_mon, :s); end - alias ldow list_dow + def lsec_(i); seq(nil, i, :comma?, :list_sec, :comma?, :s); end + def lmin_(i); seq(nil, i, :comma?, :list_min, :comma?, :s); end + def lhou_(i); seq(nil, i, :comma?, :list_hou, :comma?, :s); end + def ldom_(i); seq(nil, i, :comma?, :list_dom, :comma?, :and?, :s); end + def lmon_(i); seq(nil, i, :comma?, :list_mon, :comma?, :s); end + def ldow(i); seq(nil, i, :comma?, :list_dow, :comma?, :and?); end def _tz_name(i) rex(nil, i, / +[A-Z][a-zA-Z0-9+\-]+(\/[A-Z][a-zA-Z0-9+\-_]+){0,2}/) end def _tz_delta(i) rex(nil, i, / +[-+]([01][0-9]|2[0-4]):?(00|15|30|45)/) end def _tz(i); alt(:tz, i, :_tz_delta, :_tz_name); end def classic_cron(i) - seq(:ccron, i, :lmin_, :lhou_, :ldom_, :lmon_, :ldow, :_tz, '?') + seq(:ccron, i, + :lmin_, :lhou_, :ldom_, :lmon_, :ldow, :_tz, '?') end def second_cron(i) - seq(:scron, i, :lsec_, :lmin_, :lhou_, :ldom_, :lmon_, :ldow, :_tz, '?') + seq(:scron, i, + :lsec_, :lmin_, :lhou_, :ldom_, :lmon_, :ldow, :_tz, '?') end def cron(i) alt(:cron, i, :second_cron, :classic_cron) end @@ -819,9 +832,10 @@ hcron = st .subgather(nil) # list min, hou, mon, ... .inject({}) { |h, tt| h[tt.name] = tt.name == :tz ? rewrite_tz(tt) : rewrite_entry(tt) h } + hcron[:&] = true if t.string.index('&') z, tz = hcron[:tz]; return nil if z && ! tz hcron end