From 53161e95e59cbeee2ceb87900e17b799e840e575 Mon Sep 17 00:00:00 2001 From: Stuart Longland Date: Wed, 15 Feb 2012 17:56:27 +1000 Subject: [PATCH 1/2] faces: Fix 24-hour and end-at-midnight timespans In cases where a working day either: - Spans 24 hours or - ends at midnight the time span calculation code incorrectly calculates the time of that day, either stating that the day is 0 minutes long, or worse, is negative. The following patch addresses this. Non-working days are specified using the Python 'None', or 'False' values, rather than specifying the same start and end time, as the latter will now be interpreted as a 24-hour period. --- resource/faces/pcalendar.py | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-) diff --git a/resource/faces/pcalendar.py b/resource/faces/pcalendar.py index c82c49d..4b02391 100755 --- a/resource/faces/pcalendar.py +++ b/resource/faces/pcalendar.py @@ -895,7 +895,16 @@ class Calendar(object): def _recalc_working_time(self): def slot_sum_time(day): slots = self.working_times.get(day, DEFAULT_WORKING_DAYS[day]) - return sum(map(lambda slot: slot[1] - slot[0], slots)) + def time_diff(times): + (start, end) = times + if end == start: + return 24*60 # 24 hours + + diff = end - start + if end < start: + diff += (24*60) + return diff + return sum(map(time_diff, slots)) self.day_times = map(slot_sum_time, range(0, 7)) self.week_time = sum(self.day_times) -- 1.7.3.4