例 – Date_Holidays の使用例

基本的な例

この例は、2004 年の復活祭の日付を計算するものです。

<?php
require_once "Date/Holidays.php";
$germany = &Date_Holidays::factory('Germany'2004'en_EN');
if (
Date_Holidays::isError($germany)) {
    die(
'ファクトリでドライバオブジェクトを作成できませんでした');
}
$easter = &$germany->getHoliday('easter''de_DE');
if (!
Date_Holidays::isError($easter)) {
    
print_r($easter->toArray());
}
?>

これは、次のような配列を返します。

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] =>
                )

        )

)
Date_Holidays にできること (Previous) Date_HumanDiff (Next)
Last updated: Wed, 27 Aug 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

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";
}