From e2e14a6d053c6cd181555ec9ac878bc0e2f6de4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roger=20Ertesv=C3=A5g?= Date: Fri, 12 Jun 2009 16:02:55 +0800 Subject: [PATCH] Use 0-6 instead of sun-sat Signed-off-by: Javan Makhmali --- lib/outputs/cron.rb | 8 ++++---- test/cron_test.rb | 36 ++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/outputs/cron.rb b/lib/outputs/cron.rb index 4dce47b0..63944723 100644 --- a/lib/outputs/cron.rb +++ b/lib/outputs/cron.rb @@ -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}" diff --git a/test/cron_test.rb b/test/cron_test.rb index cc6065f9..c643e757 100644 --- a/test/cron_test.rb +++ b/test/cron_test.rb @@ -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) @@ -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