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:
		
							parent
							
								
									1cd603c65f
								
							
						
					
					
						commit
						1cd95db0ba
					
				
					 2 changed files with 10 additions and 4 deletions
				
			
		| 
						 | 
					@ -18,12 +18,15 @@ Let's start with a Person:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
A Person object knows the age of the person:
 | 
					A Person object knows the age of the person:
 | 
				
			||||||
  
 | 
					  
 | 
				
			||||||
  >>> john.age
 | 
					  >>> john.age is None
 | 
				
			||||||
 | 
					  True
 | 
				
			||||||
  >>> from datetime import date
 | 
					  >>> from datetime import date
 | 
				
			||||||
  >>> john.birthDate = date(1980, 3, 25)
 | 
					  >>> john.birthDate = date(1980, 3, 25)
 | 
				
			||||||
  >>> john.age
 | 
					  >>> now = date(2006, 5, 12)
 | 
				
			||||||
 | 
					  >>> john.ageAt(now)
 | 
				
			||||||
  26
 | 
					  26
 | 
				
			||||||
 | 
					  >>> john.age >= 26
 | 
				
			||||||
 | 
					  True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  >>> john.firstName = u'John'
 | 
					  >>> john.firstName = u'John'
 | 
				
			||||||
  >>> john.firstName
 | 
					  >>> john.firstName
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -45,9 +45,12 @@ class Person(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def age(self):
 | 
					    def age(self):
 | 
				
			||||||
 | 
					        return self.ageAt(date.today())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def ageAt(self, date):
 | 
				
			||||||
        if self.birthDate is None:
 | 
					        if self.birthDate is None:
 | 
				
			||||||
            return None
 | 
					            return None
 | 
				
			||||||
        return int((date.today() - self.birthDate).days/365.25)
 | 
					        return int((date - self.birthDate).days/365.25)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Address(object):
 | 
					class Address(object):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue