Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
B

business-time

> 编程语言
Open source

Carbon mixin to handle business days and opening hours

319 stars0 likes1 views
WebsiteGitHub

About

Carbon mixin to handle business days and opening hours

business-time

Carbon mixin to handle business days and opening hours Professionally supported nesbot/carbon is now available

Install

bash
composer require cmixin/business-time

Usage

First load the mixin in some global bootstrap place of your app:

…

Try in the live editor

Business days methods are now available on any Carbon instance used anywhere later.

Features

By enabling BusinessTime you automatically benefit on every holidays features of BusinessDay, see cmixin/business-day

As soon as you set opening hours (using the second parameter of BusinessTime::enable(), Carbon::setOpeningHours([...]) or $carbonDate->setOpeningHours([...])), you'll be able to retrieve opening hours on any Carbon instance or statically ($carbonDate->getOpeningHours() or Carbon::getOpeningHours()) as an instance of OpeningHours (spatie/opening-hours), see spatie/opening-hours for complete list of features of this class.

Then with opening hours, you'll get the following methods directly available on Carbon instances:

Holidays

By default, holidays has no particular opening hours, it will use the opening hours of the current day of week, but you can use the 'holidaysAreClosed' => true option to close the business on every holiday that is not specified otherwise in the 'exceptions' option. Else you can use a custom exception handler to link holidays or any dynamic calculation as below:

…

Try in the live editor

Multiple business-hours

To work with multiple schedules or to use all the features without loading globally the mixin into Carbon, you can create Schedule instances:

…

Try in the live editor

isOpenOn

Allows to know if the business is usually on open on a given day.

php
Carbon::isOpenOn('monday') // Returns true if there is at least 1 open range of
                           // hours set for Monday (in the regular schedule)
                           // Carbon::MONDAY would also works

$date->isOpenOn('monday') // Same as above but using local config of $date

Carbon::isOpenOn('2020-09-03') // Returns true if there is at least 1 open range of
                               // hours set for the date 2020-09-03 (considering both
                               // the regular schedule and the exceptions)

isClosedOn

Opposite of isOpenOn

php
Carbon::isClosedOn('monday')
Carbon::isClosedOn('2020-09-03')
$date->isClosedOn('monday')

isOpen

Allows to know if the business is usually on open at a given moment.

php
Carbon::isOpen()       // returns true if the business is now open
$carbonDate->isOpen()  // returns true if the business is open at the current date and time

if (Carbon::isOpen()) {
  $closingTime = Carbon::nextClose()->isoFormat('LT');
  echo "It's now open and until $closingTime.";
}

isClosed

Opposite of isOpen

php
Carbon::isClosed()       // returns true if the business is now closed
$carbonDate->isClosed()  // returns true if the business is closed at the current date and time

if (Carbon::isClosed()) {
  $openingTime = Carbon::nextClose()->calendar();
  echo "It's now closed and will re-open $openingTime.";
}

nextOpen

Go to next open-business time.

php
Carbon::nextOpen()       // go to next open time from now
$carbonDate->nextOpen()  // go to next open time from $carbonDate

nextClose

Go to next closed-business time.

php
Carbon::nextClose()       // go to next close time from now
$carbonDate->nextClose()  // go to

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言