From aa29ec8643cfabf578663e32dfe067ebdfc92394 Mon Sep 17 00:00:00 2001 From: Daniel Weschke Date: Tue, 9 Feb 2021 16:51:05 +0100 Subject: [PATCH] add a list of days function --- src/pylib/date.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/pylib/date.py b/src/pylib/date.py index 314d956..ce923b6 100644 --- a/src/pylib/date.py +++ b/src/pylib/date.py @@ -158,3 +158,27 @@ def pentecost(year): :rtype: datetime.date""" day = easter_sunday(year) + datetime.timedelta(days=+49) return day + +def daylist(day, end, excludedweekdays=[], excludeddays=[], inclusive=True): + """Create a list of dates + + :param day: the beginning day for the list + :type day: datetime.date + :param end: the end day of the list + :type end: datetime.date + :param excludedweekdays: list of days of the week to exclude, where + Monday == 1 and Sunday == 7 (ISO weekday, default = []) + :type excludedweekdays: list of int + :param excludeddays: list of days to exclude, e.g. vacation, sick + leaves, trainings (default = []) + :type excludedweekdays: list of datetime.date + :param inclusive: include the end day in the list (default = True) + :type inclusive: bool + """ + # TODO: includeddays: e.g. work on weekend days if using excludedweekdays + result = [] + while day <= end if inclusive else day < end: + if day.isoweekday() not in excludedweekdays and day not in excludeddays: + result.append(day) + day += datetime.timedelta(days=1) + return result