encoredigitalgroup / business-hours
Requires
- php: ^8.3
- cmixin/business-day: ^1.20
- encoredigitalgroup/stdlib: ^2.11
- illuminate/support: ^11|^12
- spatie/opening-hours: ^4.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.9
- larastan/larastan: ^3
- neronmoon/scriptsdev: ^0.1.9
- orchestra/testbench: ^10
- pestphp/pest: ^3
- phpgenesis/devutilities: ^1.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^2
- rector/rector: ^2
- tightenco/duster: ^3.0
- tomasvotruba/cognitive-complexity: ^1.0
This package is auto-updated.
Last update: 2025-08-14 02:22:47 UTC
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.