You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TimeRecurrence() get_next() and get_prev() Behaviour
The docstrings for the get_next() and get_prev() state the following.
"Return the next timepoint after this timepoint in the recurrence series, or None." "Return the previous timepoint before this timepoint in the recurrence series, or None."
However, this only seems to work properly when providing a TimePoint that itself is a valid time in the recurrence series.
If you pass a TimePoint that isn't a valid TimePoint within the series, the methods will return the given TimePoint with the cycle duration added/subtracted, rather than returning None which I think should be the expected behaviour based on the docstrings.
# Example where the given TimePoint does exist within the series.date_time=parse.TimePointParser().parse('2000-01-01T00:00Z')
print(date_time)
print(recurrence.get_next(date_time))
print("Is this a valid TimePoint in this recurrence series?")
print(recurrence.get_is_valid(recurrence.get_next(date_time)))
2000-01-01T00:00:00Z
2004-01-01T00:00:00Z
Is this a valid TimePoint in this recurrence series?
True
# Example where the given TimePoint does not exist in the series.date_time=parse.TimePointParser().parse('2001-01-01T00:00Z')
print(date_time)
print(recurrence.get_next(date_time))
print("Is this a valid TimePoint in this recurrence series?")
print(recurrence.get_is_valid(recurrence.get_next(date_time)))
2001-01-01T00:00:00Z
2005-01-01T00:00:00Z
Is this a valid TimePoint in this recurrence series?
False
# Example where the given TimePoint does not exist in the series.date_time=parse.TimePointParser().parse('2007-01-01T00:00Z')
print(date_time)
print(recurrence.get_prev(date_time))
print("Is this a valid TimePoint in this recurrence series?")
print(recurrence.get_is_valid(recurrence.get_prev(date_time)))
2007-01-01T00:00:00Z
2003-01-01T00:00:00Z
Is this a valid TimePoint in this recurrence series?
False
I think changing self.get_is_in_bounds() to self.get_is_valid in
defget_next(self, timepoint: "TimePoint") ->"TimePoint":
"""Return the next timepoint after this timepoint in the recurrence series, or None."""ifself._repetitions==1ortimepointisNone:
returnNonenext_timepoint=timepoint+self._durationifself._get_is_in_bounds(next_timepoint):
returnnext_timepointreturnNonedefget_prev(self, timepoint: "TimePoint") ->"TimePoint":
"""Return the previous timepoint before this timepoint in the recurrence series, or None."""ifself._repetitions==1ortimepointisNone:
returnNoneprev_timepoint=timepoint-self._durationifself._get_is_in_bounds(prev_timepoint):
returnprev_timepointreturnNone
The text was updated successfully, but these errors were encountered:
Hi Ronnie, yes thanks I've already been using TimeRecurrence().get_first_after() and it works very nicely. A get_first_before() would be a great addition too!
TimeRecurrence() get_next() and get_prev() Behaviour
The docstrings for the
get_next()
andget_prev()
state the following."Return the next timepoint after this timepoint in the recurrence series, or None."
"Return the previous timepoint before this timepoint in the recurrence series, or None."
However, this only seems to work properly when providing a
TimePoint
that itself is a valid time in the recurrence series.If you pass a TimePoint that isn't a valid TimePoint within the series, the methods will return the given TimePoint with the cycle duration added/subtracted, rather than returning
None
which I think should be the expected behaviour based on the docstrings.I think changing
self.get_is_in_bounds()
toself.get_is_valid
inisodatetime/metomi/isodatetime/data.py
Line 280 in 3216eb0
The text was updated successfully, but these errors were encountered: