This library provides functionality to check Hong Kong public holidays and manage holiday data caching.
To install the library, use Composer:
composer require hostlink/calendar
To initialize the Holiday
class, you can specify the language (en
, tc
, sc
) and an optional cache instance.
use HostLink\Calendar\Holiday;
//en: English, tc: Traditional Chinese, sc: Simplified Chinese
$holiday = new Holiday("en");
Clears the cached holiday data.
$holiday->clearCache();
Fetches the holiday data. If the data is not cached, it will download it from the internet and cache it for one month.
$data = $holiday->getData();
Checks if a given date is a holiday.
$isHoliday = $holiday->isHoliday("2023-12-25");
Gets the holidays within a specified date range.
$holidays = $holiday->getRange("2023-01-01", "2023-12-31");
use HostLink\Calendar\Holiday;
$holiday = new Holiday("en");
// Check if a specific date is a holiday
if ($holiday->isHoliday("2023-12-25")) {
echo "It's a holiday!";
} else {
echo "It's not a holiday.";
}
// Get holidays within a date range
$holidays = $holiday->getRange("2023-01-01", "2023-12-31");
foreach ($holidays as $holiday) {
echo $holiday["date"] . ": " . $holiday["name"] . "\n";
}
This project is licensed under the MIT License.