app/Date.php
public static function getAge(Date $d1, Date $d2 = null): string
    {
        if ($d2 instanceof self) {
            if ($d2->maximumJulianDay() >= $d1->minimumJulianDay() && $d2->minimumJulianDay() <= $d1->maximumJulianDay()) {
                // Overlapping dates
                $jd = $d1->minimumJulianDay();
            } else {
                // Non-overlapping dates
                $jd = $d2->minimumJulianDay();
            }
        } else {
            // If second date not specified, use today’s date
            $jd = Carbon::now()->julianDay();
        }

        // Just years, in local digits, with warning for negative/
        if ($jd && $d1->minimumJulianDay()) {
            if ($d1->minimumJulianDay() > $jd) {
                return view('icons/warning');
            }

            $years = $d1->minimumDate()->getAge($jd);

            return I18N::number($years);
        }

        return '';
    }
public static function getAge(Date $d1, Date $d2 = null): string
    {
        if ($d2 instanceof self) {
            if ($d2->maximumJulianDay() >= $d1->minimumJulianDay() && $d2->minimumJulianDay() <= $d1->maximumJulianDay()) {
                // Overlapping dates
                $jd = $d1->minimumJulianDay();
            } else {
                // Non-overlapping dates
                $jd = $d2->minimumJulianDay();
            }
        } else {
            // If second date not specified, use today’s date
            $jd = Carbon::now()->julianDay();
        }

        // Just years, in local digits, with warning for negative/
        if ($jd && $d1->minimumJulianDay()) {
            if ($d1->minimumJulianDay() > $jd) {
                return view('icons/warning');
            }

            $years = $d1->minimumDate()->getAge($jd);

            return I18N::number($years);
        }

        return '';
    }
public static function getAge ( Date $ d1 , Date $ d2 = null ) : string { if ( $ d2 instanceof self ) { if ( $ d2 -> maximumJulianDay ( ) >= $ d1 -> minimumJulianDay ( ) && $ d2 -> minimumJulianDay ( ) <= $ d1 -> maximumJulianDay ( ) ) { // Overlapping dates $ jd = $ d1 -> minimumJulianDay ( ) ; } else { // Non-overlapping dates $ jd = $ d2 -> minimumJulianDay ( ) ; } } else { // If second date not specified, use today’s date $ jd = Carbon :: now ( ) -> julianDay ( ) ; } // Just years, in local digits, with warning for negative/ if ( $ jd && $ d1 -> minimumJulianDay ( ) ) { if ( $ d1 -> minimumJulianDay ( ) > $ jd ) { return view ( 'icons/warning' ) ; } $ years = $ d1 -> minimumDate ( ) -> getAge ( $ jd ) ; return I18N :: number ( $ years ) ; } return '' ; }
Calculate the the age of a person, on a date.

@param Date      $d1
@param Date|null $d2

@return string
Calculate the the age of a person on a date .