百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
B

business-time

> 编程语言
开源

Carbon mixin 用于处理工作日和开放时间

319 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

Carbon mixin 用于处理工作日和开放时间

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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