cmelda/holidays
Composer 安装命令:
composer require cmelda/holidays
包简介
Holidays and Name's day by country
README 文档
README
Install
composer require cmelda/holidays
List of available countries
Map legend: green = public holidays and name's days, orange = public holidays only.
Map source: Blank map of Europe (without disputed regions).svg, Wikimedia Commons, CC BY-SA 4.0.
Usage
Public Holiday
$holidays = new \Cmelda\Holidays\Holidays('cze');
$date = new DateTimeImmutable();
$day = $holidays->getDay($date);
try {
$publicHolidays = $day->getPublicHolidays();
} catch (\Cmelda\Holidays\Exceptions\NoPublicHolidayException $e) {
// no public holiday
}
Name's day
$holidays = new \Cmelda\Holidays\Holidays('cze');
$date = new DateTimeImmutable();
$day = $holidays->getDay($date);
try {
$names = $day->getNames();
} catch (\Cmelda\Holidays\Exceptions\NotImplementedException $e) {
// name-day calendar is not implemented for this country
} catch (\Cmelda\Holidays\Exceptions\NoNameException $e) {
// no name's day
}
Public holidays and name's days are maintained separately. A country can be supported
for public holidays even when its name's day calendar is not available; in that case
getPublicHolidays() works and getNames() throws NotImplementedException.
NoNameException is used only when a name's day calendar is implemented, but the
selected date has no name's day.
Name's day calendars are available only for countries that have a matching
src/names/{iso}.json data file. The supported countries map uses green for
countries with both public holidays and name's days, and orange for public
holidays only.
Day
$date = new DateTimeImmutable();
$day = new \Cmelda\Holidays\Day($date);
try {
$names = $day->getNames('cze');
} catch (\Cmelda\Holidays\Exceptions\NotImplementedException $e) {
// name-day calendar is not implemented for this country
} catch (\Cmelda\Holidays\Exceptions\NoNameException $e) {
// no name's day
}
try {
$names = $day->getNames('svk');
} catch (\Cmelda\Holidays\Exceptions\NotImplementedException $e) {
// name-day calendar is not implemented for this country
} catch (\Cmelda\Holidays\Exceptions\NoNameException $e) {
// no name's day
}
Business day calculation
use Cmelda\Holidays\BusinessDayCalculator;
$calculator = new BusinessDayCalculator('cze');
$calculator->isWeekend(new DateTimeImmutable('2024-12-21')); // true
$calculator->isHoliday(new DateTimeImmutable('2024-12-24')); // true
$calculator->isWorkingDay(new DateTimeImmutable('2024-12-27')); // true
$nextWorkingDay = $calculator->nextWorkingDay(new DateTimeImmutable('2024-12-24'));
echo $nextWorkingDay->format('Y-m-d'); // 2024-12-27
$afterOneWorkingDay = $calculator->addWorkingDays(
new DateTimeImmutable('2024-03-28'),
1,
);
echo $afterOneWorkingDay->format('Y-m-d'); // 2024-04-02
$includingStartDay = $calculator->addWorkingDays(
new DateTimeImmutable('2024-03-27'),
1,
true,
);
echo $includingStartDay->format('Y-m-d'); // 2024-03-27
If you need all calculations to use a specific timezone, pass it to the constructor:
use Cmelda\Holidays\BusinessDayCalculator;
$calculator = new BusinessDayCalculator(
'cze',
new DateTimeZone('Europe/Prague'),
);
License
Distributed under the MIT License. See LICENSE.txt for more information.
Donation
cmelda/holidays 适用场景与选型建议
cmelda/holidays 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 06 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「time」 「date」 「calendar」 「datetime」 「holiday」 「holidays」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cmelda/holidays 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cmelda/holidays 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cmelda/holidays 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tools to convert between .NET and PHP date formats
A modern PHP library for generating iCalendar v2.0 events
Adds the EDTF data type to Wikibase
A powerful event calendar Tool for Laravel's Nova 5.
Date component is a set of methods to help with the manipulation of dates.
Check for holidays - localeaware
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-25

