Skip to content

Commit

Permalink
Solve 'every day at 5:00pm' issue, gh-81
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Nov 3, 2022
1 parent 9e96c67 commit d2b5d23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/fugit/nat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,20 @@ 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
Expand Down Expand Up @@ -477,12 +478,16 @@ def rewrite_to_omonthday(t)

def adjust_h(h, ap)
h = h.to_i
ap = ap || ''
(h < 12 && ap == 'pm' || ap == 'midnight') ? h + 12 : h
case ap
when 'pm' then h < 12 ? h + 12 : h
when 'midnight' then h + 12
else h
end
end

def rewrite_digital_hour(t)
h, m, ap = t.strinpd.split(/[: \t]+/)
h, m = t.sublookup(:digital_h).strinpd.split(':')
ap = t.sublookup(:ampm); ap = ap && ap.strinpd
h, m = adjust_h(h, ap), m.to_i
slot(:hm, h, m)
end
Expand Down
6 changes: 6 additions & 0 deletions spec/nat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
#
# gh-42

'every day at 5pm' => '0 17 * * *',
'every day at 5:00pm' => '0 17 * * *',
'every day at 5:00 pm' => '0 17 * * *',
#
# gh-81

#'every day at 18:15 and 20:45' => '* * * * *',
#
# gh-24 see below
Expand Down

0 comments on commit d2b5d23

Please sign in to comment.