Обновить last_friday_datetime.py

This commit is contained in:
Шимченко 2025-07-02 14:19:53 +00:00
parent bc3d92f1b4
commit 39d141df78

View File

@ -1,14 +1,12 @@
from datetime import datetime, timedelta from datetime import datetime, timedelta
def get_last_friday(a: str) -> str: def get_last_friday(a: str) -> str:
date = datetime.strptime(a, "%m/%Y").date() date = datetime.strptime(a, "%m/%Y").date()
next_month = date.replace(day=28) + timedelta(days=7) next_month = date.replace(day=28) + timedelta(days=7)
last_day = next_month - timedelta(days=next_month.day) last_day = next_month - timedelta(days=next_month.day)
# Идем назад до пятницы # Идем назад до пятницы
while last_day.weekday() != 4: while last_day.weekday() != 4:
last_day -= timedelta(days=1) last_day -= timedelta(days=1)
return last_day.strftime("%d.%m.%Y") return last_day.strftime("%d.%m.%Y")
print(get_last_friday("05/2022"))