Advertisement
DeaD_EyE

next_birthday

Oct 11th, 2022
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import calendar
  2. import datetime
  3.  
  4.  
  5. def next_date(date: datetime.date, today: datetime.date | None = None) -> datetime.date:
  6.     if today is None:
  7.         today = datetime.date.today()
  8.  
  9.     if date.month == 2 and date.day == 29:
  10.         if not calendar.isleap(today.year):
  11.             this_year = datetime.date(today.year, 3, 1)
  12.  
  13.         if not calendar.isleap(today.year + 1):
  14.             next_year = datetime.date(today.year + 1, 3, 1)
  15.     else:
  16.         this_year = datetime.date(today.year, date.month, date.day)
  17.         next_year = datetime.date(today.year + 1, date.month, date.day)
  18.  
  19.     return next_year if today >= this_year else this_year
  20.  
  21.  
  22. print(next_date(datetime.date(2004, 10, 12)))
  23. print(next_date(datetime.date(1984, 2, 29)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement