encoredigitalgroup/business-hours
最新稳定版本:v0.1.2
Composer 安装命令:
composer require encoredigitalgroup/business-hours
包简介
README 文档
README
Business Hours is a PHP library that provides a type-safe wrapper around spatie/opening-hours and cmixin/business-day. It allows you to manage business hours, holidays, and exceptions in a robust, object-oriented way.
Features
- Type-safe configuration of business hours for each day of the week
- Support for holidays and exceptions
- Integration with Spatie OpeningHours and BusinessDay for advanced time calculations
Requirements
- PHP 8.3 or higher
Installation
Install via Composer:
composer require encoredigitalgroup/business-hours
Usage
Basic Setup
use EncoreDigitalGroup\BusinessHours\BusinessHours; $config = BusinessHours::config();
Configuring Business Hours
Below is an example of how to set business hours and how to set exceptions to those business hours.
use EncoreDigitalGroup\StdLib\Objects\Calendar\DayOfWeek; use Carbon\Carbon; #You can also use Illuminate\Support\Carbon // Set Monday hours $config->day(DayOfWeek::Monday)->addHours("09:00", "17:00"); // Set exceptions $config->exceptions()->adjustedHours(Carbon::parse("2025-07-04"), "08:00", "14:00:", "4th of July"); $config->exceptions()->closed(Carbon::parse("2025-12-25"), "Christmas Day");
Adding Holidays
Below is an example of how to create and configure a holiday. When creating the holiday, the library will automatically register the date as a closed exception.
use Carbon\Carbon; $config->holidays()->region("global")->add(Carbon::parse("2025-12-25"), "christmas", "Christmas Day", true);
Checking If a Date Is a Holiday
use Carbon\Carbon; Carbon::parse("2025-12-25")->isHoliday(); // true
Testing
This project uses PestPHP for testing. To run the test suite:
vendor/bin/pest
Contributing
Contributions are welcome! Please submit pull requests and ensure all tests pass.
License
License information can be found in the LICENSE.md file.
统计信息
- 总下载量: 1.86k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2025-08-13