Skip to content

Commit

Permalink
Merge pull request llazzaro#228 from indevgr/227-normalize-end
Browse files Browse the repository at this point in the history
Normalize end date in Event._get_occurrence_list
  • Loading branch information
llazzaro authored Jul 28, 2016
2 parents a41a14b + 921ea36 commit 0cb031b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion schedule/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ def _get_occurrence_list(self, start, end):

rule = self.get_rrule_object(tzinfo)
start = (start - difference).replace(tzinfo=None)
end = (end - difference).replace(tzinfo=None)
end = (end - difference)
if timezone.is_aware(end):
end = tzinfo.normalize(end).replace(tzinfo=None)
o_starts = []
o_starts.append(rule.between(start, end, inc=True))
o_starts.append(rule.between(start - (difference // 2), end - (difference // 2), inc=True))
Expand Down
21 changes: 21 additions & 0 deletions tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,27 @@ def test_recurring_event_get_occurrence_in_timezone(self):
occurrence = event.get_occurrence(start)
self.assertEqual(occurrence.start, start)

def test_recurring_event_get_occurrence_different_end_timezone(self):
end_recurring = datetime.datetime(2016, 7, 30, 11, 0, tzinfo=pytz.utc)

event = self.__create_recurring_event(
'Recurring event with end_reccurring_date in different TZ',
datetime.datetime(2016, 7, 25, 10, 0, tzinfo=pytz.utc),
datetime.datetime(2016, 7, 25, 11, 0, tzinfo=pytz.utc),
end_recurring,
Rule.objects.create(frequency="DAILY"),
Calendar.objects.create(name='MyCal'),
)
event.save()

tzinfo = pytz.timezone('Europe/Athens')
occurrences = event.get_occurrences(
tzinfo.localize(datetime.datetime(2016, 1, 1, 0, 0)),
tzinfo.localize(datetime.datetime(2016, 12, 31, 23, 59)),
)
self.assertEqual(occurrences[-1].end, end_recurring)


def test_(self):
pass

Expand Down

0 comments on commit 0cb031b

Please sign in to comment.