refactor: use $this->difference()

This commit is contained in:
kenjis 2022-06-21 15:55:07 +09:00
parent efef8eb702
commit 4e7c3df956
No known key found for this signature in database
GPG Key ID: BD254878922AF198

View File

@ -460,12 +460,8 @@ class Time extends DateTime
*/ */
public function getAge() public function getAge()
{ {
$now = self::now();
$age = (int) (((int) $now->format('Ymd') - (int) $this->format('Ymd')) / 10000);
// future dates have no age // future dates have no age
return max(0, $age); return max(0, $this->difference(self::now())->getYears());
} }
/** /**