Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Fix generation of all-day events to include repeat end date
Browse files Browse the repository at this point in the history
The prior fix to RRULE generation of repeat all-day events to include
the repeat end date did not apply to the `generate()` generator method
which uses the `between()` method to constrain generated datetimes. So
we apply the same kind of fix in a second place with subtle differences
due to the different inclusion/exclusion rules between RRULE specs and
the python `rruleset.between()` method.
  • Loading branch information
jmurty committed Oct 18, 2016
1 parent e43a172 commit 56cac19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
10 changes: 8 additions & 2 deletions icekit_events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@ def __str__(self):
def generate(self, until=None):
"""
Return a list of datetime objects for event occurrence start and end
times, up to the given ``until`` parameter or up to the configured
``REPEAT_LIMIT`` for unlimited events.
times, up to the given ``until`` parameter, or up to the ``repeat_end``
time, or to the configured ``REPEAT_LIMIT`` for unlimited events.
"""
# Get starting datetime just before this event's start date or time
# (must be just before since start & end times are *excluded* by the
Expand All @@ -528,6 +528,12 @@ def generate(self, until=None):
until = self.repeat_end
else:
until = djtz.now() + appsettings.REPEAT_LIMIT
# For all-day occurrence generation, make the `until` constraint
# the next date from of the repeat end date to ensure the end
# date is included in the generated set as users expect (and
# remembering the `between` method used below is exclusive).
if self.is_all_day:
until += timedelta(days=1)
# Make datetimes naive, since RRULE spec contains naive datetimes so
# our constraints must be the same
start_dt = coerce_naive(start_dt)
Expand Down
11 changes: 11 additions & 0 deletions icekit_events/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,17 @@ def test_daily_repeating_every_day_in_month(self):
self.assertTrue(coerce_naive(start) in rruleset)
self.assertTrue(
coerce_naive(djtz.datetime(2016,10,31, 0,0)) in rruleset)
# Repeating generator `generate` method produces expected date entries
start_and_end_times_list = list(generator.generate())
self.assertEqual(31, len(start_and_end_times_list))
self.assertEqual(
(coerce_naive(start),
coerce_naive(end) + timedelta(days=1, microseconds=-1)),
start_and_end_times_list[0])
self.assertEqual(
(coerce_naive(repeat_end),
coerce_naive(repeat_end) + timedelta(days=1, microseconds=-1)),
start_and_end_times_list[-1])


class TestEventOccurrences(TestCase):
Expand Down

0 comments on commit 56cac19

Please sign in to comment.