add a list of days function

This commit is contained in:
2021-02-09 16:51:05 +01:00
parent b08728f54c
commit aa29ec8643

View File

@@ -158,3 +158,27 @@ def pentecost(year):
:rtype: datetime.date""" :rtype: datetime.date"""
day = easter_sunday(year) + datetime.timedelta(days=+49) day = easter_sunday(year) + datetime.timedelta(days=+49)
return day 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