lib/fugit/nat.rb in fugit-1.7.1 vs lib/fugit/nat.rb in fugit-1.7.2

- old
+ new

@@ -174,10 +174,11 @@ #'every month on days 1,15 at 10:00' => '0 10 1,15 * *', # #'every week on monday 18:23' => '23 18 * * 1', # # every month on the 1st + # def on(i) seq(:on, i, :_on, :on_objects) end def city_tz(i) @@ -194,23 +195,24 @@ end def tzone(i) seq(nil, i, :_in_or_on, '?', :tz) end - def digital_hour(i) - rex( - :digital_hour, i, - /(2[0-4]|[0-1]?[0-9]):([0-5][0-9])([ \t]*(am|pm))?/i) - end - def ampm(i) rex(:ampm, i, /[ \t]*(am|pm|noon|midday|midnight)/i) end def dark(i) rex(:dark, i, /[ \t]*dark/i) end + def digital_h(i) + rex(:digital_h, i, /(2[0-4]|[0-1]?[0-9]):([0-5][0-9])/i) + end + def digital_hour(i) + seq(:digital_hour, i, :digital_h, :ampm, '?') + end + def simple_h(i) rex(:simple_h, i, /#{(0..24).to_a.reverse.join('|')}/) end def simple_hour(i) seq(:simple_hour, i, :simple_h, :ampm, '?') @@ -449,49 +451,67 @@ else fail "cannot rewrite #{s.inspect}" end end def rewrite_tz(t) + slot(:tz, t.string) end def rewrite_weekday(t) + Fugit::Cron::Parser::WEEKDS.index(t.string[0, 3].downcase) end def rewrite_weekdays(t) + #Raabro.pp(t, colours: true) slot(:weekday, _rewrite_subs(t, :weekday)) end alias rewrite_on_weekdays rewrite_weekdays def rewrite_to_weekday(t) + wd0, wd1 = _rewrite_subs(t, :weekday) #wd1 = 7 if wd1 == 0 slot(:weekday, "#{wd0}-#{wd1}") end def rewrite_to_omonthday(t) md0, md1 = _rewrite_subs(t, :omonthday).collect(&:_data0) slot(:monthday, "#{md0}-#{md1}") end - def adjust_h(h, ap) - h = h.to_i - ap = ap || '' - (h < 12 && ap == 'pm' || ap == 'midnight') ? h + 12 : h + # Try to follow https://en.wikipedia.org/wiki/12-hour_clock#Confusion_at_noon_and_midnight + # + def adjust_h(h, m, ap) + + if ap == 'midnight' && h == 12 + 24 + elsif ap == 'pm' && h < 12 # post meridian + h + 12 + elsif ap == 'am' && h == 12 # ante meridian + 0 + else + h + end end def rewrite_digital_hour(t) - h, m, ap = t.strinpd.split(/[: \t]+/) - h, m = adjust_h(h, ap), m.to_i + + h, m = t.sublookup(:digital_h).strinpd.split(':').collect(&:to_i) + ap = t.sublookup(:ampm) + h, m = adjust_h(h, m, ap && ap.strinpd), m + slot(:hm, h, m) end def rewrite_simple_hour(t) + h, ap = t.subgather(nil).collect(&:strinpd) - h = adjust_h(h, ap) + h = adjust_h(h.to_i, 0, ap) + slot(:hm, h, 0) end def rewrite_named_hour(t) @@ -499,15 +519,13 @@ mt = t.sublookup(:named_m) apt = t.sublookup(:ampm) h = ht.strinp m = mt ? mt.strinp : 0 -#p [ 0, '-->', h, m ] h = NHOURS[h] m = NMINUTES[m] || m -#p [ 1, '-->', h, m ] - h = adjust_h(h, apt && apt.strinpd) + h = adjust_h(h, m, apt && apt.strinpd) slot(:hm, h, m) end def rewrite_to_hour(t)