Commit 22488f0d 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 5fd3bd99
Pipeline #7698 running with stage
...@@ -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 \
...@@ -171,7 +172,7 @@ class PresencePeriod(Movement, PeriodicityMixin): ...@@ -171,7 +172,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()})
# Update the next exception date # Update the next exception date
if len(exception_date_list) != 0: if len(exception_date_list) != 0:
...@@ -182,7 +183,7 @@ class PresencePeriod(Movement, PeriodicityMixin): ...@@ -182,7 +183,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)
...@@ -207,12 +208,21 @@ class PresencePeriod(Movement, PeriodicityMixin): ...@@ -207,12 +208,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