1
0
Fork 0
forked from s3lph/matemat

Remplaced a calendar function not available in Python 3.6

This commit is contained in:
s3lph 2018-11-03 21:22:25 +01:00
parent fe1f52a954
commit 726b4a9370

View file

@ -20,7 +20,7 @@ def add_months(d: datetime, months: int) -> datetime:
days: int = 0 days: int = 0
# Iterate the months between the passed date and the target month # Iterate the months between the passed date and the target month
for i in range(months): for i in range(months):
days += calendar.monthlen(*nextmonth) days += calendar.monthrange(*nextmonth)[1]
nextmonth = calendar.nextmonth(*nextmonth) nextmonth = calendar.nextmonth(*nextmonth)
# Set the day of month temporarily to 1, then add the day offset to reach the 1st of the target month # Set the day of month temporarily to 1, then add the day offset to reach the 1st of the target month
newdate: datetime = d.replace(day=1) + timedelta(days=days) newdate: datetime = d.replace(day=1) + timedelta(days=days)