From 5f933e0188f2bc69f4e2b394844667d187cda26f Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Fri, 7 Dec 2012 11:23:21 +0100 Subject: [PATCH] [IMP] resource: small improvement of Stuart's time_diff function bzr revid: rco@openerp.com-20121207102321-3e4rp9562on0zspg --- addons/resource/faces/pcalendar.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/addons/resource/faces/pcalendar.py b/addons/resource/faces/pcalendar.py index 4b023911b1e..de7bf251c1b 100644 --- a/addons/resource/faces/pcalendar.py +++ b/addons/resource/faces/pcalendar.py @@ -893,17 +893,13 @@ class Calendar(object): #@-node:_build_mapping #@+node:_recalc_working_time def _recalc_working_time(self): + def time_diff(times): + diff = times[1] - times[0] + if diff <= 0: # happens when times span across midnight + diff += 24*60 + return diff def slot_sum_time(day): slots = self.working_times.get(day, DEFAULT_WORKING_DAYS[day]) - 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))