Skip to content

Commit

Permalink
Merge branch 'integration'
Browse files Browse the repository at this point in the history
  • Loading branch information
javan committed Jun 26, 2009
2 parents 6fbb125 + e2e14a6 commit 2a44d2a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions lib/outputs/cron.rb
Expand Up @@ -85,11 +85,11 @@ def parse_as_string
timing[0] = @at.is_a?(Time) ? @at.min : 0
timing[1] = @at.is_a?(Time) ? @at.hour : 0

return (timing << 'mon-fri') * " " if string.downcase.index('weekday')
return (timing << 'sat,sun') * " " if string.downcase.index('weekend')
return (timing << '1-5') * " " if string.downcase.index('weekday')
return (timing << '6,0') * " " if string.downcase.index('weekend')

%w(sun mon tue wed thu fri sat).each do |day|
return (timing << day) * " " if string.downcase.index(day)
%w(sun mon tue wed thu fri sat).each_with_index do |day, i|
return (timing << i) * " " if string.downcase.index(day)
end

raise ArgumentError, "Couldn't parse: #{@time}"
Expand Down
36 changes: 18 additions & 18 deletions test/cron_test.rb
Expand Up @@ -136,13 +136,13 @@ class CronTest < Test::Unit::TestCase
context "When parsing time in days (of week)" do
should "parse days of the week correctly" do
{
'sun' => %w(sun Sunday SUNDAY SUN),
'mon' => %w(mon Monday MONDAY MON),
'tue' => %w(tue tues Tuesday TUESDAY TUE),
'wed' => %w(wed Wednesday WEDNESDAY WED),
'thu' => %w(thu thurs thur Thursday THURSDAY THU),
'fri' => %w(fri Friday FRIDAY FRI),
'sat' => %w(sat Saturday SATURDAY SAT)
'0' => %w(sun Sunday SUNDAY SUN),
'1' => %w(mon Monday MONDAY MON),
'2' => %w(tue tues Tuesday TUESDAY TUE),
'3' => %w(wed Wednesday WEDNESDAY WED),
'4' => %w(thu thurs thur Thursday THURSDAY THU),
'5' => %w(fri Friday FRIDAY FRI),
'6' => %w(sat Saturday SATURDAY SAT)
}.each do |day, day_tests|
day_tests.each do |day_test|
assert_equal "0 0 * * #{day}", parse_time(day_test)
Expand All @@ -151,23 +151,23 @@ class CronTest < Test::Unit::TestCase
end

should "allow additional directives" do
assert_equal '30 13 * * fri', parse_time('friday', nil, "1:30 pm")
assert_equal '22 2 * * mon', parse_time('Monday', nil, "2:22am")
assert_equal '55 17 * * thu', parse_time('THU', nil, "5:55PM")
assert_equal '30 13 * * 5', parse_time('friday', nil, "1:30 pm")
assert_equal '22 2 * * 1', parse_time('Monday', nil, "2:22am")
assert_equal '55 17 * * 4', parse_time('THU', nil, "5:55PM")
end

should "parse weekday correctly" do
assert_equal '0 0 * * mon-fri', parse_time('weekday')
assert_equal '0 0 * * mon-fri', parse_time('Weekdays')
assert_equal '0 1 * * mon-fri', parse_time('Weekdays', nil, "1:00 am")
assert_equal '59 5 * * mon-fri', parse_time('Weekdays', nil, "5:59 am")
assert_equal '0 0 * * 1-5', parse_time('weekday')
assert_equal '0 0 * * 1-5', parse_time('Weekdays')
assert_equal '0 1 * * 1-5', parse_time('Weekdays', nil, "1:00 am")
assert_equal '59 5 * * 1-5', parse_time('Weekdays', nil, "5:59 am")
end

should "parse weekend correctly" do
assert_equal '0 0 * * sat,sun', parse_time('weekend')
assert_equal '0 0 * * sat,sun', parse_time('Weekends')
assert_equal '0 7 * * sat,sun', parse_time('Weekends', nil, "7am")
assert_equal '2 18 * * sat,sun', parse_time('Weekends', nil, "6:02PM")
assert_equal '0 0 * * 6,0', parse_time('weekend')
assert_equal '0 0 * * 6,0', parse_time('Weekends')
assert_equal '0 7 * * 6,0', parse_time('Weekends', nil, "7am")
assert_equal '2 18 * * 6,0', parse_time('Weekends', nil, "6:02PM")
end
end

Expand Down

0 comments on commit 2a44d2a

Please sign in to comment.