more on organize.person's age attribute

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1209 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2006-05-12 19:45:21 +00:00
parent 1cd603c65f
commit 1cd95db0ba
2 changed files with 10 additions and 4 deletions

View file

@ -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

View file

@ -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):