From 0a207996cd5553456e010545c3032da7517b8673 Mon Sep 17 00:00:00 2001 From: Nicolas Delaby <nicolas@nexedi.com> Date: Wed, 24 Oct 2007 16:50:42 +0000 Subject: [PATCH] Add new parameter to compare rounded date, needed for accounting git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17176 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/DateUtils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/product/ERP5Type/DateUtils.py b/product/ERP5Type/DateUtils.py index d1cc1a2aad..298a14a7d2 100644 --- a/product/ERP5Type/DateUtils.py +++ b/product/ERP5Type/DateUtils.py @@ -215,15 +215,23 @@ def getCompletedMonthBetween(from_date=None, to_date=None, return getIntervalBetweenDates(from_date = from_date, to_date = to_date, keys = {'month':1} ) -def getRoundedMonthBetween(from_date=None, to_date=None): +def getRoundedMonthBetween(from_date=None, to_date=None, rounded_day=False): """ Return a rounded number of months between the both given dates. + rounded_day is usefull for accounting, eg: + the duration between 2000/01/01 23:30 and 2000/01/02 08:00 + is 1 day, not 0.35 day """ return_value = getIntervalBetweenDates(from_date = from_date, to_date = to_date, keys = {'month':1} )['month'] from_date = addToDate(from_date, {'month': return_value} ) end_date = addToDate(from_date, {'month':1} ) days_in_month = end_date - from_date - if to_date - from_date >= days_in_month / 2.: + if rounded_day: + from math import ceil + interval_day = ceil(to_date - from_date) + else: + interval_day = to_date - from_dat + if interval_day >= days_in_month / 2.: return_value += 1 return return_value -- 2.30.9