sakai/jp-holiday
Composer 安装命令:
composer require sakai/jp-holiday
包简介
Japanese national holidays library for PHP
README 文档
README
English
Japanese national holidays library for PHP.
Verified against the National Astronomical Observatory of Japan (NAO) official data.
Requirements
- PHP 7.1+
Installation
composer require sakai/jp-holiday
Usage
use Sakai\JpHoliday\JpHoliday; $date = new DateTimeImmutable('2024-01-01'); JpHoliday::isHoliday($date); // true JpHoliday::getName($date); // '元日' JpHoliday::getNameEn($date); // "New Year's Day" JpHoliday::getDescription($date); // '年のはじめを祝う。'
Get Full Holiday Info
$info = JpHoliday::getHolidayInfo($date); // ['name' => '元日', 'name_en' => "New Year's Day", 'description' => '...']
Get All Holidays in a Year
$holidays = JpHoliday::getHolidaysInYear(2024); // ['2024-01-01' => [...], '2024-01-08' => [...], ...]
Get Holidays in Date Range
$holidays = JpHoliday::between( new DateTimeImmutable('2024-04-01'), new DateTimeImmutable('2024-05-31') );
DateTime / DateTimeImmutable / Carbon
Any class implementing DateTimeInterface is supported.
API
| Method | Returns | Description |
|---|---|---|
isHoliday($date) |
bool |
Whether the date is a holiday |
getName($date) |
?string |
Holiday name in Japanese |
getNameEn($date) |
?string |
Holiday name in English |
getDescription($date) |
?string |
Holiday description in Japanese |
getHolidayInfo($date) |
?array |
Full holiday info array |
getHolidaysInYear($year) |
array |
All holidays in a year |
between($start, $end) |
array |
Holidays within date range |
Configuration
Limit date ranges for between() to prevent DoS:
JpHoliday::configure(['maxBetweenDays' => 365]); // Limit to 365 days JpHoliday::getConfig(); // ['maxBetweenDays' => 365] JpHoliday::resetConfig(); // Reset to default (no limit)
Supported Holidays
- Fixed holidays (New Year's Day, National Foundation Day, etc.)
- Happy Monday holidays (Coming of Age Day, Marine Day, etc.)
- Equinox days (Vernal/Autumnal Equinox Day)
- Substitute holidays (振替休日)
- Citizen's holidays (国民の休日)
- Special: 2019 Imperial transition, 2020/2021 Olympics
Limitations
This library only supports dates from July 20, 1948 onwards, when the National Holidays Act (国民の祝日に関する法律) was enacted. Dates before this will return empty/null.
Data Sources & Maintenance
Equinox dates (Vernal Equinox Day, Autumnal Equinox Day) are hardcoded based on official announcements from the National Astronomical Observatory of Japan. The dates are published in the "Reki-yoko" (暦要項) around February 1st each year for the following year.
References:
- 国立天文台 暦要項 - Official equinox dates
- 国立天文台 FAQ - About equinox calculation
- 祝日の計算方法 - Reference for historical data
Note: This library requires annual updates to add new equinox dates. Please check for updates or contribute if you notice missing data.
License
MIT
日本語
日本の祝日を判定するPHPライブラリ
国立天文台 暦要項の公式データで検証済み。
必要環境
- PHP 7.1以上
インストール
composer require sakai/jp-holiday
使い方
use Sakai\JpHoliday\JpHoliday; $date = new DateTimeImmutable('2024-01-01'); JpHoliday::isHoliday($date); // true JpHoliday::getName($date); // '元日' JpHoliday::getNameEn($date); // "New Year's Day" JpHoliday::getDescription($date); // '年のはじめを祝う。'
祝日情報をまとめて取得
$info = JpHoliday::getHolidayInfo($date); // ['name' => '元日', 'name_en' => "New Year's Day", 'description' => '...']
1年分の祝日を取得
$holidays = JpHoliday::getHolidaysInYear(2024); // ['2024-01-01' => [...], '2024-01-08' => [...], ...]
期間内の祝日を取得
$holidays = JpHoliday::between( new DateTimeImmutable('2024-04-01'), new DateTimeImmutable('2024-05-31') );
DateTime / DateTimeImmutable / Carbon 対応
DateTimeInterface を実装していればどの日付クラスでも使用可能。
API
| メソッド | 戻り値 | 説明 |
|---|---|---|
isHoliday($date) |
bool |
祝日かどうか |
getName($date) |
?string |
祝日名(日本語) |
getNameEn($date) |
?string |
祝日名(英語) |
getDescription($date) |
?string |
祝日の説明 |
getHolidayInfo($date) |
?array |
祝日情報配列 |
getHolidaysInYear($year) |
array |
1年分の祝日 |
between($start, $end) |
array |
期間内の祝日 |
グローバル設定
between() の日数制限でDoS対策:
JpHoliday::configure(['maxBetweenDays' => 365]); // 最大365日に制限 JpHoliday::getConfig(); // ['maxBetweenDays' => 365] JpHoliday::resetConfig(); // デフォルトにリセット(無制限)
対応する祝日
- 固定祝日(元日、建国記念の日など)
- ハッピーマンデー(成人の日、海の日など)
- 春分の日・秋分の日
- 振替休日
- 国民の休日
- 特例: 2019年皇位継承、2020/2021年オリンピック
制限事項
このライブラリは国民の祝日に関する法律が施行された1948年7月20日以降の日付のみ対応しています。それ以前の日付は空/nullを返します。
データソース・メンテナンス
春分の日・秋分の日は、国立天文台の公式発表に基づきハードコードしています。日付は毎年2月1日頃に翌年分が「暦要項」で発表されます。
参照:
注意: このライブラリは毎年の更新が必要です。データの不足に気づいた場合は、更新の確認またはコントリビュートをお願いします。
ライセンス
MIT
Author / 作者
Kiyoshi Sakai
Related / 関連
- jp-holiday - JavaScript/TypeScript version / JS/TS版
sakai/jp-holiday 适用场景与选型建议
sakai/jp-holiday 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「calendar」 「japanese」 「japan」 「holiday」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sakai/jp-holiday 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sakai/jp-holiday 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sakai/jp-holiday 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Translate comments in laravel/laravel 5.* project to Japanese
A modern PHP library for generating iCalendar v2.0 events
Japanese MyNumber (Individual Number / Corporate Number) verifier
A powerful event calendar Tool for Laravel's Nova 5.
Check for holidays - localeaware
Faker Japanese is a Faker provider that generates fake Japanese related data for you.
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-08