add a list of days function
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user