ice_cube
ice_cube copied to clipboard
previous_occurrence misses if occurrence not a full day behind
I am attempting to use previous_occurrence()
with a date that is 1ms in front of the first occurrence but it does not detect it. It's almost like previous_occurrence only finds occurrences that are at least 1 day behind. Is there a way to allow previous_occurrence
to evaluate based on time rather than just date?
Below is an example showing how the first occurrence is due at 11:59pm on dec 31st but checking for previous occurrences from jan 1 doesn't find it.
schedule = IceCube::Schedule.new(Date.parse('01-01-2018').end_of_day - 1.day) do |s|
s.add_recurrence_rule(IceCube::Rule.monthly(6))
end
schedule.first # Sun, 31 Dec 2017 23:59:59 UTC +00:00
schedule.previous_occurrence(Date.parse('01-01-2018')) # nil
The smallest unit that IceCube works with is 1 second: milliseconds are dropped.
I think here because you are trying to jump from 00:00:00
to the previous occurrence at 23:59:59.99999
, it's jumping back to 23:59:59
which is before the range of the schedule.
I think we are not normalizing the start time when we check that boundary: looks like an edge case.