From 82cb2ea6ee024847d885c431cfccaa404c4bf648 Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Mon, 21 Feb 2022 09:42:32 -0400 Subject: [PATCH] Make timezone aware when needed --- program/models.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/program/models.py b/program/models.py index 0efbb998..ecf3eb59 100644 --- a/program/models.py +++ b/program/models.py @@ -415,9 +415,8 @@ class Schedule(models.Model): starts.append(timezone.make_aware(datetime.combine(schedule.dstart, schedule.tstart))) ends.append(timezone.make_aware(datetime.combine(dend, schedule.tend))) else: - starts = list(rrule(freq=schedule.rrule.freq, - dtstart=timezone.make_aware(datetime.combine(schedule.dstart, schedule.tstart)), + dtstart=datetime.combine(schedule.dstart, schedule.tstart), interval=schedule.rrule.interval, until=schedule.until + relativedelta(days=+1), bysetpos=schedule.rrule.bysetpos, @@ -425,7 +424,7 @@ class Schedule(models.Model): byweekno=byweekno)) ends = list(rrule(freq=schedule.rrule.freq, - dtstart=timezone.make_aware(datetime.combine(dend, schedule.tend)), + dtstart=datetime.combine(dend, schedule.tend), interval=schedule.rrule.interval, until=schedule.until + relativedelta(days=+1), bysetpos=schedule.rrule.bysetpos, @@ -439,7 +438,7 @@ class Schedule(models.Model): # produces wrong end dates if the 1st Tuesday is before the 1st Monday # In this case we take the next day instead of rrule's calculated end if starts[k] > ends[k]: - ends[k] = timezone.make_aware(datetime.combine(starts[k] + relativedelta(days=+1), schedule.tend)) + ends[k] = datetime.combine(starts[k] + relativedelta(days=+1), schedule.tend) ''' Add a number of days to the generated dates? @@ -477,8 +476,8 @@ class Schedule(models.Model): if ends[k].date() > schedule.until: schedule.until = ends[k].date() - - timeslots.append(TimeSlot(schedule=schedule, start=starts[k], end=ends[k]).generate()) + timeslots.append( + TimeSlot(schedule=schedule, start=timezone.make_aware(starts[k]), end=timezone.make_aware(ends[k])).generate()) return timeslots -- GitLab