diff --git a/lib/tickle/tickle.rb b/lib/tickle/tickle.rb index 5c0bb4b..fef16f5 100644 --- a/lib/tickle/tickle.rb +++ b/lib/tickle/tickle.rb @@ -50,7 +50,7 @@ def _parse( tickled ) # check to see if this event starts some other time and reset now scan_expression! tickled - fail(InvalidDateExpression, "the start date (#{@start.to_date}) cannot occur in the past for a future event") if @start && @start.to_date < Date.today + fail(InvalidDateExpression, "the start date (#{@start.to_date}) cannot occur in the past for a future event") if @start && @start.to_date < tickled.now.to_date fail(InvalidDateExpression, "the start date (#{@start.to_date}) cannot occur after the end date") if @until && @start.to_date > @until.to_date # no need to guess at expression if the start_date is in the future @@ -75,7 +75,7 @@ def _parse( tickled ) # if we can't guess it maybe chronic can _guess = guess(@tokens, @start) - best_guess = _guess || chronic_parse(tickled.event) # TODO fix this call + best_guess = _guess || chronic_parse(tickled.event) # TODO fix this call end fail(InvalidDateExpression, "the next occurrence takes place after the end date specified") if @until && (best_guess.to_date > @until.to_date) @@ -131,7 +131,7 @@ def scan_expression!(tickled) fail(InvalidDateExpression,"the ending date expression \"#{tickled.ending}\" could not be interpretted") end else - @until = + @until = if tickled.starting && !tickled.starting.to_s.blank? if tickled.until && !tickled.until.to_s.blank? if tickled.until.to_time > @start diff --git a/spec/tickle_spec.rb b/spec/tickle_spec.rb index 39ee305..298c2ed 100644 --- a/spec/tickle_spec.rb +++ b/spec/tickle_spec.rb @@ -241,6 +241,14 @@ module Tickle # for convenience end end + context "Given that start is in the past, respect now option in parse" do + context "every other day" do + subject{ Tickle.parse('every other day', {:start=>Time.parse("2009-05-09 00:00:00 -4000"), :now=>Time.parse("2009-05-09 00:00:00 -4000"), :until=>Time.parse("2017-10-21 00:00:00 -4000") }) } + let(:expected) { {:next=>Time.parse("2009-05-11 00:00:00 -4000"), :expression=>"every other day", :starting=>Time.parse("2009-05-09 00:00:00 -4000"), :until=>nil} } + it { should == expected } + end + end + context "Given that now is in the future, 2020-04-01 00:00:00 +0000" do context "February" do subject{ Tickle.parse('February', {:start=>Time.parse("2020-04-01 00:00:00 +0000"), :now=>Time.parse("2020-04-01 00:00:00 +0000")}) }