refactor: optimize date handling by replacing manual conditions with datetime functions

This commit is contained in:
Wawa 2024-09-17 09:52:14 +02:00 committed by GitHub
parent ea9f4d79b0
commit 2a4422b678
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,40 +1,14 @@
import time
from datetime import datetime
from datetime import datetime, timedelta
import datetime
def decalageDate(baseURL, decalage):
today = datetime.datetime.today()
future_date = datetime.datetime.today() + datetime.timedelta(days=decalage)
day = today.day
year = today.year
month = today.month
formatted_date = future_date.strftime("%Y-%m-%d")
if month in [1, 3, 5, 7, 8, 10, 12]:
max_days = 31
elif month == 2:
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
max_days = 29
else:
max_days = 28
else:
max_days = 30
url = baseURL + formatted_date
if day + decalage > max_days:
if month + 1 > 12:
year = year + 1
month = 1
day = day + decalage - max_days
url = baseURL + str(year) + "-" + str(month).zfill(2) + "-" + str(day).zfill(2)
print(url)
return url
else:
day = day + decalage - max_days
url = baseURL + str(year) + "-" + str(month).zfill(2) + "-" + str(day).zfill(2)
print(url)
return url
else:
day = day + decalage
url = baseURL + str(year) + "-" + str(month).zfill(2) + "-" + str(day).zfill(2)
print(url)
return url
print(url)
return (url)