Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
birth certifiDate solution in Clear category for Next Birthday by veky
from datetime import date, timedelta
class Person:
def __init__(self, name, birth_date, today):
self.name = name
birth_date, today = date(*birth_date), date(*today)
nbd = birthday_in_year(birth_date, today.year)
if nbd < today: nbd = birthday_in_year(birth_date, today.year + 1)
self.following_age = nbd.year - birth_date.year
self.days_till_birthday = (nbd - today).days
def birthday_in_year(birth_date, year):
try: return birth_date.replace(year)
except ValueError: return birthday_in_year(birth_date + timedelta(1), year)
def next_birthday(today, birthdates):
people = {Person(name, ymd, today) for name, ymd in birthdates.items()}
min_days = min(person.days_till_birthday for person in people)
return min_days, {person.name: person.following_age for person in people
if person.days_till_birthday == min_days}
Sept. 10, 2020
Comments: