From 59799302bd00952ee3d2f9388b6d763ebeb1cb75 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 21 Feb 2017 13:57:04 -0600 Subject: [PATCH] Fix daylight savings bug when cloning schedule from previous week --- tailbone/views/shifts/schedule.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tailbone/views/shifts/schedule.py b/tailbone/views/shifts/schedule.py index 2509053f..4dcbfc01 100644 --- a/tailbone/views/shifts/schedule.py +++ b/tailbone/views/shifts/schedule.py @@ -169,11 +169,20 @@ class ScheduleView(TimeSheetView): .filter(model.ScheduledShift.start_time >= make_utc(start_time))\ .filter(model.ScheduledShift.end_time < make_utc(end_time)) for shift in shifts: + + # must calculate new times using date as base, b/c of daylight savings + start_time = localtime(self.rattail_config, shift.start_time, from_utc=True) + start_time = datetime.datetime.combine(start_time.date() + offset, start_time.time()) + start_time = localtime(self.rattail_config, start_time) + end_time = localtime(self.rattail_config, shift.end_time, from_utc=True) + end_time = datetime.datetime.combine(end_time.date() + offset, end_time.time()) + end_time = localtime(self.rattail_config, end_time) + Session.add(model.ScheduledShift( employee_uuid=shift.employee_uuid, store_uuid=shift.store_uuid, - start_time=shift.start_time + offset, - end_time=shift.end_time + offset, + start_time=make_utc(start_time), + end_time=make_utc(end_time), )) copied += 1