Skip to content

Commit

Permalink
Make #until works correctly with Date objects
Browse files Browse the repository at this point in the history
Closes #118
  • Loading branch information
seejohnrun committed Nov 13, 2012
1 parent baaae6d commit b7a265b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/ice_cube/time_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ def self.now
end

# Ensure that this is either nil, or a time
def self.ensure_time(time)
def self.ensure_time(time, date_eod = false)
case time
when Date, DateTime then time.to_time
when DateTime then time.to_time
when Date then date_eod ? time.to_time.end_of_day : time.to_time
else time
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/validations/until.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def until_time
deprecated_alias :until_date, :until_time

def until(time)
@until = TimeUtil.ensure_time time
@until = time = TimeUtil.ensure_time time, true
replace_validations_for(:until, time.nil? ? nil : [Validation.new(time)])
self
end
Expand Down
6 changes: 6 additions & 0 deletions spec/examples/regression_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,10 @@
schedule.occurrences_between(start_time, end_time).first.should == start_time
end

it 'should include occurrences on until _date_ [#118]' do
schedule = IceCube::Schedule.new Time.new(2012, 4, 27)
schedule.rrule IceCube::Rule.daily.hour_of_day(12).until(Date.new(2012, 4, 28))
schedule.all_occurrences.should == [Time.new(2012, 4, 27, 12), Time.new(2012, 4, 28, 12)]
end

end

0 comments on commit b7a265b

Please sign in to comment.