Fixed bug where :at directives were being ignored when using named periods
Signed-off-by: Javan Makhmali <javan@javan.us>
This commit is contained in:
parent
18186fa0eb
commit
33ec97886b
@ -72,11 +72,15 @@ module Whenever
|
||||
return unless @time
|
||||
string = @time.to_s
|
||||
|
||||
return "0 0 * * mon-fri" if string.downcase.index('weekday')
|
||||
return "0 0 * * sat,sun" if string.downcase.index('weekend')
|
||||
timing = Array.new(4, '*')
|
||||
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')
|
||||
|
||||
%w(sun mon tue wed thu fri sat).each do |day|
|
||||
return "0 0 * * #{day}" if string.downcase.index(day)
|
||||
return (timing << day) * " " if string.downcase.index(day)
|
||||
end
|
||||
|
||||
raise ArgumentError, "Couldn't parse: #{@time}"
|
@ -150,14 +150,20 @@ class CronTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
should "allow additional directives" do
|
||||
assert_equal '30 13 * * fri', parse_time('friday', nil, "1:30 pm")
|
||||
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")
|
||||
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")
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user