Commit dc7d52ec 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

(cherry picked from commit 30e2c1f6cb55ae3dfc4d8c83911b53f38a6cc36d)
parent ec6372a4
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
from copy import copy from copy import copy
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from DateTime import DateTime
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5.mixin.periodicity import PeriodicityMixin from Products.ERP5.mixin.periodicity import PeriodicityMixin
...@@ -149,8 +150,8 @@ class PresencePeriod(Movement, PeriodicityMixin): ...@@ -149,8 +150,8 @@ class PresencePeriod(Movement, PeriodicityMixin):
stop_date = self.getStopDate(start_date) stop_date = self.getStopDate(start_date)
periodicity_stop_date = self.getPeriodicityStopDate( periodicity_stop_date = self.getPeriodicityStopDate(
start_date) start_date)
second_duration = int(stop_date) - int(start_date) duration = stop_date - start_date
if second_duration > 0: if duration > 0:
# First date has to respect the periodicity config # First date has to respect the periodicity config
next_start_date = self.getNextPeriodicalDate(addToDate(start_date, day=-1)) next_start_date = self.getNextPeriodicalDate(addToDate(start_date, day=-1))
while (next_start_date is not None) and \ while (next_start_date is not None) and \
...@@ -170,8 +171,7 @@ class PresencePeriod(Movement, PeriodicityMixin): ...@@ -170,8 +171,7 @@ class PresencePeriod(Movement, PeriodicityMixin):
(current_exception_date < next_start_date.Date()): (current_exception_date < next_start_date.Date()):
# SQL method don't like iterator # SQL method don't like iterator
# yield (next_start_date, next_start_date+duration) # yield (next_start_date, next_start_date+duration)
result.append([next_start_date, result.append([next_start_date, next_start_date + duration])
addToDate(next_start_date, second=second_duration)])
# Update the next exception date # Update the next exception date
if len(exception_date_list) != 0: if len(exception_date_list) != 0:
current_exception_date = exception_date_list.pop(0).Date() current_exception_date = exception_date_list.pop(0).Date()
...@@ -181,7 +181,7 @@ class PresencePeriod(Movement, PeriodicityMixin): ...@@ -181,7 +181,7 @@ class PresencePeriod(Movement, PeriodicityMixin):
# SQL method don't like iterator # SQL method don't like iterator
# yield (next_start_date, next_start_date+duration) # yield (next_start_date, next_start_date+duration)
result.append({'start_date': next_start_date, 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()}) 'quantity': self.getQuantity()})
next_start_date = self.getNextPeriodicalDate(next_start_date) next_start_date = self.getNextPeriodicalDate(next_start_date)
...@@ -206,12 +206,21 @@ class PresencePeriod(Movement, PeriodicityMixin): ...@@ -206,12 +206,21 @@ class PresencePeriod(Movement, PeriodicityMixin):
day_count = int(current_date-next_start_date) day_count = int(current_date-next_start_date)
next_start_date = next_start_date + day_count 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: while 1:
if (self._validateDay(next_start_date)) and \ if (self._validateDay(next_start_date)) and \
(self._validateWeek(next_start_date)) and \ (self._validateWeek(next_start_date)) and \
(self._validateMonth(next_start_date)): (self._validateMonth(next_start_date)):
break break
else: else:
next_start_date = addToDate(next_start_date, day=1) next_start_date = self._getNextDay(next_start_date, timezone)
return next_start_date
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