Commit 5b3f2426 authored by Jérome Perrin's avatar Jérome Perrin

calendar: make PresencePeriod support timezone with daylight saving

 - update PresencePeriod.getNextPeriodicalDate with fixes from 6155f7ff
 - do not use addToDate, but simply DateTime arithmetics that unlike addToDate, works correctly
parent 2b3d4ce7
......@@ -31,6 +31,7 @@
from copy import copy
from AccessControl import ClassSecurityInfo
from DateTime import DateTime
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5.mixin.periodicity import PeriodicityMixin
......@@ -145,15 +146,15 @@ class PresencePeriod(Movement, PeriodicityMixin):
stop_date = self.getStopDate(start_date)
periodicity_stop_date = self.getPeriodicityStopDate(
start_date)
second_duration = int(stop_date) - int(start_date)
if second_duration > 0:
duration = stop_date - start_date
if duration > 0:
# First date has to respect the periodicity config
next_start_date = self.getNextPeriodicalDate(addToDate(start_date, day=-1))
while (next_start_date is not None) and \
(next_start_date <= periodicity_stop_date):
if next_start_date.Date() not in exception_date_set:
result.append({'start_date': next_start_date,
'stop_date': addToDate(next_start_date, second=second_duration),
'stop_date': next_start_date + duration,
'quantity': self.getQuantity()})
next_start_date = self.getNextPeriodicalDate(next_start_date)
......@@ -178,12 +179,21 @@ class PresencePeriod(Movement, PeriodicityMixin):
day_count = int(current_date-next_start_date)
next_start_date = next_start_date + day_count
next_start_date = addToDate(next_start_date, day=1)
timezone = self._getTimezone(next_start_date)
next_start_date = self._getNextDay(next_start_date, timezone)
while 1:
if (self._validateDay(next_start_date)) and \
(self._validateWeek(next_start_date)) and \
(self._validateMonth(next_start_date)):
break
else:
next_start_date = addToDate(next_start_date, day=1)
return next_start_date
next_start_date = self._getNextDay(next_start_date, timezone)
return DateTime(
next_start_date.year(),
next_start_date.month(),
next_start_date.day(),
current_date.hour(),
current_date.minute(),
current_date.second(),
timezone)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment