From 56cac190e2cd61bff5d31fb2888b23f6887361ce Mon Sep 17 00:00:00 2001 From: James Murty Date: Wed, 19 Oct 2016 07:24:07 +1100 Subject: [PATCH] Fix generation of all-day events to include repeat end date 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. --- icekit_events/models.py | 10 ++++++++-- icekit_events/tests/tests.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/icekit_events/models.py b/icekit_events/models.py index 4041cd5..a96ad21 100644 --- a/icekit_events/models.py +++ b/icekit_events/models.py @@ -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 @@ -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) diff --git a/icekit_events/tests/tests.py b/icekit_events/tests/tests.py index a6ac52b..9365d14 100644 --- a/icekit_events/tests/tests.py +++ b/icekit_events/tests/tests.py @@ -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):