Are there potential pitfalls or errors that can arise when calculating age in PHP using Unix timestamps and not accounting for leap years?

When calculating age in PHP using Unix timestamps without accounting for leap years, the calculated age may be off by one year for individuals born on a leap day (February 29th). To solve this issue, we can adjust the calculation by checking if the birth date falls on a leap day and if the current year is a leap year.

function calculateAge($birthDate){
    $birthTimestamp = strtotime($birthDate);
    $now = time();
    
    $age = date('Y', $now) - date('Y', $birthTimestamp);
    
    $birthDateThisYear = date('Y') . date('-m-d', $birthTimestamp);
    if(date('L', strtotime($birthDateThisYear)) && date('m-d', $birthTimestamp) == '02-29'){
        if(date('m-d', $now) != '02-29'){
            $age--;
        }
    }
    
    return $age;
}

// Example usage
$birthDate = '1992-02-29';
echo calculateAge($birthDate); // Output: Correctly calculates age even for leap day births