diff --git a/lib/cron_parser.rb b/lib/cron_parser.rb index 41a8a5e..355bdee 100644 --- a/lib/cron_parser.rb +++ b/lib/cron_parser.rb @@ -136,7 +136,7 @@ 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 =~ /^\*/ @@ -144,10 +144,12 @@ def parse_element(elem, allowed_range) 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 diff --git a/lib/parse-cron/version.rb b/lib/parse-cron/version.rb index c256e8e..3718610 100644 --- a/lib/parse-cron/version.rb +++ b/lib/parse-cron/version.rb @@ -1,5 +1,5 @@ module Parse module Cron - VERSION = "0.1.4" + VERSION = "0.1.5" end end diff --git a/spec/cron_parser_spec.rb b/spec/cron_parser_spec.rb index 94f7ad0..4046b77 100644 --- a/spec/cron_parser_spec.rb +++ b/spec/cron_parser_spec.rb @@ -78,6 +78,8 @@ def parse_date(str) ["15-59/15 * * * *", "2014-02-01 15:45", "2014-02-01 16:15",4], ["15-59/15 * * * *", "2014-02-01 15:46", "2014-02-01 16:15",3], ["15-59/15 * * * *", "2014-02-01 15:46", "2014-02-01 16:15",2], + ["15/15 * * * *", "2014-02-01 15:46", "2014-02-01 16:15",1], + ["15/15 * * * *", "2014-02-01 15:44", "2014-02-01 15:45",1] ].each do |line, now, expected_next,num| it "returns #{expected_next} for '#{line}' when now is #{now}" do parsed_now = parse_date(now) @@ -157,6 +159,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"] ].each do |line, now, expected_next| it "should return #{expected_next} for '#{line}' when now is #{now}" do now = parse_date(now)