From 9dfc0e4078003582b43e56a2f5c74474947048fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20T=C3=A4nzer?= Date: Tue, 21 Jun 2011 01:12:54 +0200 Subject: [PATCH] Correctly calculate age MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michael Tänzer --- manager/application/models/User.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/manager/application/models/User.php b/manager/application/models/User.php index 55eeadb..7b7a519 100644 --- a/manager/application/models/User.php +++ b/manager/application/models/User.php @@ -168,7 +168,16 @@ class Default_Model_User { */ public function getAge() { $now = new Zend_Date(); - return $now->sub($this->getDob())->toValue(Zend_Date::YEAR); + $dob = $this->getDob(); + $age = $now->get(Zend_Date::YEAR) - $dob->get(Zend_Date::YEAR); + + // Did we have a happy birthday already this year? + $dob->setYear($now); + if ($dob->compare($now) > 0) { + $age -= 1; + } + + return $age; } /**