Example

Example – Example for the usage of Date_Holidays

Basic example

This example shows you, how to calculate the Easter date of 2005.

<?php
require_once "Date/Holidays.php";
$germany = &Date_Holidays::factory('Germany'2004'en_EN');
if (
Date_Holidays::isError($germany)) {
    die(
'Factory was unable to produce driver-object');
}
$easter = &$germany->getHoliday('easter''de_DE');
if (!
Date_Holidays::isError($easter)) {
    
print_r($easter->toArray());
}
?>

This will return an array in the following format:

Array
(
    [internalName] => easter
    [title] => Easter Sunday
    [date] => date Object
        (
            [year] => 2004
            [month] => 04
            [day] => 11
            [hour] => 0
            [minute] => 0
            [second] => 0
            [tz] => date_timezone Object
                (
                    [id] => UTC
                    [longname] => Coordinated Universal Time
                    [shortname] => UTC
                    [hasdst] =>
                    [dstlongname] => Coordinated Universal Time
                    [dstshortname] => UTC
                    [offset] => 0
                    [default] =>
                )

        )

)
What Date_Holidays can do (Previous) Date_HumanDiff (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

Note by: user@example.com
When trying to get the above example to work, I receive an error message:

"Call to undefined method PEAR_Error::isHoliday()"

Also, I get a lot of deprecated messages when running PEAR with PHP 5.3!
Note by: kguest
This is an example of testing whether a specified date is considered a holiday [in Ireland].

require_once "Date/Holidays.php";
require_once "Date/Holidays/Filter/Ireland/Official.php";

//set up filter
$filter = new Date_Holidays_Filter_Ireland_Official();
//then the driver
$driver = &Date_Holidays::factory($country, $year);

//now test.
$dstr = '2007-04-06';
$workday = new Date($dstr);
if ($driver->isHoliday($workday, $filter)){
echo "{$dstr} is a holiday\n";
}