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.
- 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
- PHP 8.3 or higher
Install via Composer:
composer require encoredigitalgroup/business-hours
use EncoreDigitalGroup\BusinessHours\BusinessHours;
$config = BusinessHours::config();
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");
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);
use Carbon\Carbon;
Carbon::parse("2025-12-25")->isHoliday(); // true
This project uses PestPHP for testing. To run the test suite:
vendor/bin/pest
Contributions are welcome! Please submit pull requests and ensure all tests pass.
License information can be found in the LICENSE.md file.