Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for error thrown when using int/int format cron #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions lib/cron_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,20 @@ def last(now = @time_source.now, num=1)
end


SUBELEMENT_REGEX = %r{^(\d+)(-(\d+)(/(\d+))?)?$}
SUBELEMENT_REGEX = %r{^(\d+)((-(\d+))?(/(\d+))?)?$}
def parse_element(elem, allowed_range)
values = elem.split(',').map do |subel|
if subel =~ /^\*/
step = subel.length > 1 ? subel[2..-1].to_i : 1
stepped_range(allowed_range, step)
else
if SUBELEMENT_REGEX === subel
if $5 # with range
stepped_range($1.to_i..$3.to_i, $5.to_i)
elsif $3 # range without step
stepped_range($1.to_i..$3.to_i, 1)
if $6 && $4 # range with step
stepped_range($1.to_i..$4.to_i, $6.to_i)
elsif $6 && !$4 # step without range
stepped_range($1.to_i..allowed_range.end, $6.to_i)
elsif $4 # range without step
stepped_range($1.to_i..$4.to_i, 1)
else # just a numeric
[$1.to_i]
end
Expand Down
2 changes: 1 addition & 1 deletion lib/parse-cron/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Parse
module Cron
VERSION = "0.1.4"
VERSION = "0.1.5"
end
end
1 change: 1 addition & 0 deletions spec/cron_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def parse_date(str)
["15-59/15 * * * *", "2014-02-01 15:36", "2014-02-01 15:30"],
["15-59/15 * * * *", "2014-02-01 15:45", "2014-02-01 15:30"],
["15-59/15 * * * *", "2014-02-01 15:46", "2014-02-01 15:45"],
["15/15 * * * *", "2014-02-01 15:46", "2014-02-01 15:45"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a spec for #nextto have that covered?

].each do |line, now, expected_next|
it "should return #{expected_next} for '#{line}' when now is #{now}" do
now = parse_date(now)
Expand Down