Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Next Birthday solution in Clear category for Next Birthday by JimmyCarlos
from typing import Dict, Tuple
Date = Tuple[int, int, int]
from datetime import datetime,timedelta
def next_birthday(today: Date, birthdates: Dict[str, Date]) -> Tuple[int, Dict[str, int]]:
# Convert the today and birthdates from (Y,M,D) to datetime objects.
birthdates = {k:datetime(*v) for k,v in birthdates.items()}
today = datetime(*today)
days_passed = 0
while True:
birthdays_today = {}
for person_name,birthdate in birthdates.items():
if (birthdate.month,birthdate.day) == (today.month,today.day) or\
((birthdate.month,birthdate.day) == (2,29) and (today.month,today.day) == (3,1)):
birthdays_today[person_name] = today.year - birthdate.year
if birthdays_today:
return (days_passed, birthdays_today)
else:
today += timedelta(days=1)
days_passed += 1
Oct. 6, 2020
Comments: