What are some best practices for handling date calculations in PHP scripts, especially when considering holidays?

When handling date calculations in PHP scripts, especially when considering holidays, it is important to account for the specific dates of holidays and adjust calculations accordingly. One approach is to create an array of holiday dates and check if a given date falls within that array before performing any calculations. This ensures that the calculations are accurate and take into account holidays that may affect the result.

// Array of holiday dates
$holidays = array(
    '2022-01-01', // New Year's Day
    '2022-07-04', // Independence Day
    '2022-12-25'  // Christmas Day
);

// Function to check if a given date is a holiday
function isHoliday($date, $holidays) {
    return in_array($date, $holidays);
}

// Example calculation with consideration for holidays
$date = '2022-07-03'; // July 3rd
if (!isHoliday($date, $holidays)) {
    // Perform calculation if not a holiday
    // Calculation logic here
} else {
    echo "This date is a holiday, calculations will not be performed.";
}