PHP code example of r28 / holiday-jp

1. Go to this page and download the library: Download r28/holiday-jp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

r28 / holiday-jp example snippets



28\HolidayJp\HolidayJp;

    $date = '2019-05-01';
    $holiday = new HolidayJp($date);
    $holiday_name = $holiday->holidayName();
    echo $holiday_name.PHP_EOL;
    # 天皇即位の日
    

    $date = '2019-05-03';
    $time = new AstroTime($date, 'Asia/Tokyo', false);
    $holiday = new HolidayJp();
    $holiday_name = $holiday->holidayName($time);
    echo $holiday_name.PHP_EOL;
    # 憲法記念日
    

    $holiday_name = HolidayJp::holidayNameFromDate('2019-05-04');
    echo $holiday_name.PHP_EOL;
    # みどりの日
    

    $holiday_name = HolidayJp::holidayNameFromTimestamp(1556982000); # 2019/05/05
    echo $holiday_name.PHP_EOL;
    # こどもの日
    

    $holiday_name = HolidayJp::holidayNameFromJulian(2458609.125);  # 2019/05/06
    echo $holiday_name.PHP_EOL;
    # 振替休日
    

    $holidays = HolidayJp::holidayNamesFromYear(2019, 'date_string', true);
    print_r($holidays);

    Array
    (
        [2019-01-01] => 元日
        [2019-01-14] => 成人の日
        [2019-02-11] => 建国記念の日
        ....
        [2019-11-03] => 文化の日
        [2019-11-04] => 振替休日
        [2019-11-23] => 勤労感謝の日
    )
    

    $holidays = HolidayJp::holidayNamesFromYearMonth(2019, 5, 'date_string', true);
    print_r($holidays);

    Array
    (
        [2019-05-01] => 天皇即位の日
        [2019-05-02] => 国民の休日
        [2019-05-03] => 憲法記念日
        [2019-05-04] => みどりの日
        [2019-05-05] => こどもの日
        [2019-05-06] => 振替休日
    )
    

    $holidays = HolidayJp::itteratePeriodsFromDate('2019-01-01', '2019-04-01', 'date_string', true, false);
    print_r($holidays);

    Array
    (
        [2019-01-01] => 元日
        [2019-01-14] => 成人の日
        [2019-02-11] => 建国記念の日
        [2019-03-21] => 春分の日
    )
    

    $holidays = HolidayJp::itteratePeriodsFromDate('2019-01-01', '2019-04-01', 'date_string', true, true);
    print_r($holidays);

    Array
    (
        [2019-01-01] => Array
            (
                [name] => 元日
                [time] => r28\AstroTime\AstroTime Object
                    (
                        [timezoneName] => Asia/Tokyo
                        [local] => Cake\Chronos\Chronos Object
                            (
                                [hasFixedNow] =>
                                [time] => 2019-01-01 00:00:00.000000
                                [timezone] => Asia/Tokyo
                            )

                        [utc] => Cake\Chronos\Chronos Object
                            (
                                [hasFixedNow] =>
                                [time] => 2018-12-31 15:00:00.000000
                                [timezone] => UTC
                            )

                        [timestamp] => 1546268400
                        [calendar_type] => gregorian
                        [jd] => 2458484.125
                        [mjd] => 58483.625
                        [jc] => 0.18998288843258
    【以下略】
    )
    

    define('EXPORT_DIR', '/PATH/TO/exports/');
    HolidayJp::exportCsvForPeriodsFromDate(EXPORT_DIR, 'holidays.csv', '2018-01-01', '2031-12-31');
    
shell
    $ head /PATH/TO/exports/holidays.csv

    ---ここから---
    datetime,timestamp,name
    "2018-01-01",1514732400,元日
    "2018-01-02",1514818800,
    "2018-01-03",1514905200,
    "2018-01-04",1514991600,
    "2018-01-05",1515078000,
    "2018-01-06",1515164400,
    "2018-01-07",1515250800,
    "2018-01-08",1515337200,成人の日
    "2018-01-09",1515423600,
    ---ここまで---