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):