diff --git a/organize/README.txt b/organize/README.txt index b6bbd17..30c77b0 100644 --- a/organize/README.txt +++ b/organize/README.txt @@ -18,12 +18,15 @@ Let's start with a Person: A Person object knows the age of the person: - >>> john.age - + >>> john.age is None + True >>> from datetime import date >>> john.birthDate = date(1980, 3, 25) - >>> john.age + >>> now = date(2006, 5, 12) + >>> john.ageAt(now) 26 + >>> john.age >= 26 + True >>> john.firstName = u'John' >>> john.firstName diff --git a/organize/party.py b/organize/party.py index 7494217..5b49fa1 100644 --- a/organize/party.py +++ b/organize/party.py @@ -45,9 +45,12 @@ class Person(object): @property def age(self): + return self.ageAt(date.today()) + + def ageAt(self, date): if self.birthDate is None: return None - return int((date.today() - self.birthDate).days/365.25) + return int((date - self.birthDate).days/365.25) class Address(object):