PHP code example of chinese-holidays / holiday-checker

1. Go to this page and download the library: Download chinese-holidays/holiday-checker 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/ */

    

chinese-holidays / holiday-checker example snippets


use ChineseHolidays\HolidayChecker;

$checker = new HolidayChecker();

// 1. 判断是否为法定节假日(休息日)
$checker->isHoliday('2024-10-01'); // true (国庆节)
$checker->isHoliday('2024-10-12'); // false (国庆调休上班)

// 2. 判断是否为工作日
$checker->isWorkday('2024-10-08'); // true (周二正常上班)
$checker->isWorkday('2024-10-12'); // true (周六调休上班)
$checker->isWorkday('2024-10-01'); // false (国庆节休息)

// 3. 判断是否为日常周末
$checker->isWeekend('2024-01-13'); // true (普通周六)
$checker->isWeekend('2024-10-12'); // false (周六调休上班,非日常周末)

// 4. 获取详细信息
$info = $checker->getHolidayInfo('2024-10-01');
/*
[
    'name' => '国庆节',
    'isOffDay' => true
]
*/