You are here

public function BirthdaysBirthday::getCurrentAge in Birthdays 7

Calculates the current age.

Return value

The current age.

1 call to BirthdaysBirthday::getCurrentAge()
BirthdaysBirthday::toString in ./birthdays_birthday.inc
Converts the value to a string.

File

./birthdays_birthday.inc, line 255
The BirthdaysBirthday class.

Class

BirthdaysBirthday
Converts between different data representations and do calculations on a birthday.

Code

public function getCurrentAge($now = REQUEST_TIME) {
  if ($this->value['year'] == 0) {
    return t('Age unkown');
  }
  $months_diff = date('m', $now) - $this->value['month'];
  if ($months_diff < 0) {
    return $this
      ->getAge(date('Y', $now)) - 1;
  }
  elseif ($months_diff == 0) {
    if ($this->value['day'] > date('d', $now)) {
      return $this
        ->getAge(date('Y', $now)) - 1;
    }
  }
  return $this
    ->getAge(date('Y', $now));
}