From 1cd95db0baf0450b6494ad92f3ce152e1c29adf6 Mon Sep 17 00:00:00 2001 From: helmutm Date: Fri, 12 May 2006 19:45:21 +0000 Subject: [PATCH] more on organize.person's age attribute git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1209 fd906abe-77d9-0310-91a1-e0d9ade77398 --- organize/README.txt | 9 ++++++--- organize/party.py | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) 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):