Skip to content

Instantly share code, notes, and snippets.

@Jeffallan
Created March 21, 2018 17:05
Show Gist options
  • Save Jeffallan/7d1c04f67328f58c8c72adb8dfad2f9b to your computer and use it in GitHub Desktop.
Save Jeffallan/7d1c04f67328f58c8c72adb8dfad2f9b to your computer and use it in GitHub Desktop.
Birthday calculator
from datetime import date
class Birthday(object):
def __init__(self, year, month, day):
self.dob = date(year, month, day)
@property
def age(self):
today = date.today()
if self.dob.month > today.month:
return (today.year - self.dob.year) - 1
elif self.dob.month == today.month:
if self.dob.day > today.day:
return (today.year - self.dob.year) - 1
else:
return today.year - self.dob.year
else:
return today.year - self.dob.year
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment