Skip to content

Commit

Permalink
Accept "hour" specification with a single letter (like 8 or *). Fixed a…
Browse files Browse the repository at this point in the history
  • Loading branch information
tomykaira committed Oct 24, 2011
1 parent d1dac47 commit 57438ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/clockwork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ def exception_message(e)
def parse_at(at)
return unless at
case at
when /^(\d\d):(\d\d)$/
when /^(\d{1,2}):(\d\d)$/
hour = $1.to_i
min = $2.to_i
raise FailedToParse, at if hour >= 24 || min >= 60
[hour, min]
when /^\*\*:(\d\d)$/
when /^\*{1,2}:(\d\d)$/
min = $1.to_i
raise FailedToParse, at if min >= 60
[nil, min]
Expand Down
16 changes: 16 additions & 0 deletions test/clockwork_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def assert_wont_run(t)
assert_will_run 'jan 2 2010 16:20:00'
end

test ":at also accepts 8:20" do
Clockwork.every(1.hour, 'myjob', :at => '8:20')

assert_wont_run 'jan 1 2010 08:19:59'
assert_will_run 'jan 1 2010 08:20:00'
assert_wont_run 'jan 1 2010 08:20:01'
end

test "twice a day at 16:20 and 18:10" do
Clockwork.every(1.day, 'myjob', :at => ['16:20', '18:10'])

Expand All @@ -85,6 +93,14 @@ def assert_wont_run(t)
assert_will_run 'jan 2 2010 16:20:00'
end

test ":at also accepts *:20" do
Clockwork.every(1.hour, 'myjob', :at => '*:20')

assert_wont_run 'jan 1 2010 15:19:59'
assert_will_run 'jan 1 2010 15:20:00'
assert_wont_run 'jan 1 2010 15:20:01'
end

test "aborts when no handler defined" do
Clockwork.clear!
assert_raise(Clockwork::NoHandlerDefined) do
Expand Down

0 comments on commit 57438ae

Please sign in to comment.