Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Next Birthday by Tinus_Trotyl
from typing import Dict, Tuple; Date = Tuple[int, int, int]
def next_birthday(today: Date, birthdates: Dict[str, Date]) -> Tuple[int, Dict[str, int]]:
from datetime import date
def feb29conv(anniversary):
leap = lambda year: date(year, 3, 1).toordinal() - date(year, 1, 1).toordinal() == 60
if anniversary[1:] == (2, 29) and not leap(anniversary[0]): return anniversary[0], 3, 1
return anniversary
span = 366
for name in birthdates:
todate = date(*today).toordinal()
birthdate = birthdates[name]
birthday = (today[0],) + birthdate[1:]
anniversary = date(*feb29conv(birthday)).toordinal()
if anniversary < todate:
birthday = (today[0] + 1,) + birthday[1:]
anniversary= date(*feb29conv(birthday)).toordinal()
daycnt = anniversary - todate
if daycnt > span: continue
if daycnt < span: span, birthdays = daycnt, dict()
birthdays[name] = int(str(date.fromordinal(anniversary)).split('-')[0]) - birthdates[name][0]
return span, birthdays
Sept. 23, 2020