Exemple #1
0
 public static function getAgeByBirthDate(Date $birthDate, $actualDate = null)
 {
     if ($actualDate) {
         Assert::isInstance($actualDate, Date::class);
     } else {
         $actualDate = Date::makeToday();
     }
     $result = $actualDate->getYear() - $birthDate->getYear();
     if ($actualDate->getMonth() < $birthDate->getMonth() || $actualDate->getMonth() == $birthDate->getMonth() && $actualDate->getDay() < $birthDate->getDay()) {
         // - Happy birthday?
         // - Happy go to hell. Not yet in this year.
         --$result;
     }
     return $result;
 }
 public static function getHumanDay(Date $date, $wordDayNeed = true)
 {
     $today = Date::makeToday();
     $tomorrow = $today->spawn('+1 day');
     if ($date->toDate() == $today->toDate() && $wordDayNeed == true) {
         return 'сегодня';
     } elseif ($date->toDate() == $tomorrow->toDate() && $wordDayNeed == true) {
         return 'завтра';
     } else {
         return (int) $date->getDay() . ' ' . RussianTextUtils::getMonthInGenitiveCase($date->getMonth());
     }
 }