summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjem-odoo <jem@openerp.com>2018-03-14 10:56:28 +0100
committerNicolas Lempereur <nle@odoo.com>2018-04-03 17:54:12 +0200
commit35a4263f0a84cd11e77fa82aa3249baaa68fba96 (patch)
tree3f4320b346c13b9209218e7fe3f87869422cbfd9
parentce162fae3e078705c576ee75a1994f7d89b60180 (diff)
[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
-rw-r--r--addons/calendar/models/calendar.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/addons/calendar/models/calendar.py b/addons/calendar/models/calendar.py
index 6fcf24f2c35..6e70347a9a6 100644
--- a/addons/calendar/models/calendar.py
+++ b/addons/calendar/models/calendar.py
@@ -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