summaryrefslogtreecommitdiff
path: root/date.py
diff options
context:
space:
mode:
authorArthur Lutz <arthur.lutz@logilab.fr>2008-03-06 15:36:00 +0100
committerArthur Lutz <arthur.lutz@logilab.fr>2008-03-06 15:36:00 +0100
commitd7c5f67ee6c57331098e85762aaf852410734473 (patch)
tree5c9d391994e971ce64c7e2dd9a8053e2d84d67e0 /date.py
parentcff1ab3b0447b2c434beee22209195bc168b3ce3 (diff)
downloadlogilab-common-d7c5f67ee6c57331098e85762aaf852410734473.tar.gz
added counting of opendays between two dates
Diffstat (limited to 'date.py')
-rw-r--r--date.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/date.py b/date.py
index fd1d885..b44c8b0 100644
--- a/date.py
+++ b/date.py
@@ -16,6 +16,7 @@
"""date manipulation helper functions"""
+import math
try:
from mx.DateTime import RelativeDateTime, strptime
@@ -82,7 +83,27 @@ else:
if x.day_of_week < 5])
return end
-
+ def nb_open_days(start, end):
+ days = int(math.ceil((end - start).days))
+ weeks, plus = divmod(days, 7)
+ if start.day_of_week > end.day_of_week:
+ plus -= 2
+ elif end.day_of_week == 6:
+ plus -= 1
+ open_days = weeks * 5 + plus
+ nb_week_holidays = len([x for x in get_national_holidays(start,
+ end+1)
+ if x.day_of_week < 5])
+ return open_days - nb_week_holidays
+
+ #def nb_open_days(start, end):
+ # """ brute-force version """
+ # days = [x for x in date_range(start, end) if x.day_of_week < 5]
+ # nb_week_holidays = len([x for x in get_national_holidays(start,
+ # end+1)
+ # if x.day_of_week < 5])
+ # return len(days) - nb_week_holidays
+
def date_range(begin, end, step=STEP):
"""
enumerate dates between begin and end dates.