Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import calendar
- import datetime
- def next_date(date: datetime.date, today: datetime.date | None = None) -> datetime.date:
- if today is None:
- today = datetime.date.today()
- if date.month == 2 and date.day == 29:
- if not calendar.isleap(today.year):
- this_year = datetime.date(today.year, 3, 1)
- if not calendar.isleap(today.year + 1):
- next_year = datetime.date(today.year + 1, 3, 1)
- else:
- this_year = datetime.date(today.year, date.month, date.day)
- next_year = datetime.date(today.year + 1, date.month, date.day)
- return next_year if today >= this_year else this_year
- print(next_date(datetime.date(2004, 10, 12)))
- print(next_date(datetime.date(1984, 2, 29)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement