lib/fugit/nat.rb in fugit-1.4.5 vs lib/fugit/nat.rb in fugit-1.5.0

- old
+ new

@@ -199,11 +199,11 @@ :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)/i) + rex(:ampm, i, /[ \t]*(am|pm|noon|midday|midnight)/i) end def dark(i) rex(:dark, i, /[ \t]*dark/i) end @@ -471,21 +471,25 @@ 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 + end + def rewrite_digital_hour(t) h, m, ap = t.strinpd.split(/[: \t]+/) - h, m = h.to_i, m.to_i - h += 12 if ap && ap == 'pm' - slot(:hm, h.to_i, m.to_i) + h, m = adjust_h(h, ap), m.to_i + slot(:hm, h, m) end def rewrite_simple_hour(t) h, ap = t.subgather(nil).collect(&:strinpd) - h = h.to_i - h = h + 12 if ap == 'pm' + h = adjust_h(h, ap) slot(:hm, h, 0) end def rewrite_named_hour(t) @@ -498,10 +502,10 @@ #p [ 0, '-->', h, m ] h = NHOURS[h] m = NMINUTES[m] || m #p [ 1, '-->', h, m ] - h += 12 if h < 13 && apt && apt.strinpd == 'pm' + h = adjust_h(h, apt && apt.strinpd) slot(:hm, h, m) end def rewrite_to_hour(t)