定制 cmelda/holidays 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cmelda/holidays

Composer 安装命令:

composer require cmelda/holidays

包简介

Holidays and Name's day by country

README 文档

README

Latest Stable Version Total Downloads License PHP Version Require

Install

composer require cmelda/holidays

List of available countries

List

Map of supported 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

ko-fi

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 cmelda/holidays 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-25