[FIX] calendar: comparing timezoned datetimes
We transform the rrule stored as a string into a real rrule object using 'rrule.rrulestr'. The 'UNTIL' parameter of the rrule might not be timezoned. So the '_until' property of the rrule object will be a naive datetime. Later in the '_get_recurrent_date_by_event', we add the recurring date in the '_exdate' property, but those dates are timezoned. When iterating on the rrule set (its a set since forceset=True), the until date and exdate are compared, but it cause crashes as we can not compare offset-naive and offset-aware datetimes. This commit make the rrule use only naive or aware datetimes for its 'until' and '_exdate' properties depending on the 'until' property of calendar.event rrule field. opw-1825679 closes #24010
This commit is contained in:
committed by
Nicolas Lempereur
parent
ce162fae3e
commit
35a4263f0a
@@ -608,7 +608,8 @@ class Meeting(models.Model):
|
||||
if not event_date:
|
||||
event_date = datetime.now()
|
||||
|
||||
if self.allday and self.rrule and 'UNTIL' in self.rrule and 'Z' not in self.rrule:
|
||||
use_naive_datetime = self.allday and self.rrule and 'UNTIL' in self.rrule and 'Z' not in self.rrule
|
||||
if use_naive_datetime:
|
||||
rset1 = rrule.rrulestr(str(self.rrule), dtstart=event_date.replace(tzinfo=None), forceset=True, ignoretz=True)
|
||||
else:
|
||||
# Convert the event date to saved timezone (or context tz) as it'll
|
||||
@@ -616,9 +617,13 @@ class Meeting(models.Model):
|
||||
event_date = event_date.astimezone(timezone) # transform "+hh:mm" timezone
|
||||
rset1 = rrule.rrulestr(str(self.rrule), dtstart=event_date, forceset=True, tzinfos={})
|
||||
recurring_meetings = self.search([('recurrent_id', '=', self.id), '|', ('active', '=', False), ('active', '=', True)])
|
||||
|
||||
for meeting in recurring_meetings:
|
||||
rset1._exdate.append(todate(meeting.recurrent_id_date))
|
||||
recurring_date = fields.Datetime.from_string(meeting.recurrent_id_date)
|
||||
if use_naive_datetime:
|
||||
recurring_date = recurring_date.replace(tzinfo=None)
|
||||
else:
|
||||
recurring_date = todate(meeting.recurrent_id_date)
|
||||
rset1.exdate(recurring_date)
|
||||
return [d.astimezone(pytz.UTC) if d.tzinfo else d for d in rset1]
|
||||
|
||||
@api.multi
|
||||
|
||||
Reference in New Issue
Block a user