Skip to content

Commit

Permalink
Improve age calculation (#326)
Browse files Browse the repository at this point in the history
Program still crashes when dob > now
  • Loading branch information
rogererens authored and MatthieuDartiailh committed Oct 25, 2018
1 parent f94a8df commit 2a6caab
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions examples/tutorial/employee/employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ def update_age(self, change):
age = now.year - self.dob.year
# check to see if the current date is before their birthday and
# subtract a year from their age if it is
if now.month >= self.dob.month and now.day > self.dob.day:
age -= 1
if ((now.month == self.dob.month and now.day < self.dob.day)
or now.month < self.dob.month):
age -= 1
# set the persons age
self.age = age

Expand Down

0 comments on commit 2a6caab

Please sign in to comment.