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

business

> 编程语言
Open source

:date: DateTime calculations in business hours

360 stars0 likes0 views
WebsiteGitHub

About

:date: DateTime calculations in business hours

Business Build status Version PHP Version

DateTime calculations in business hours

Installation

bash
$ composer require florianv/business

Usage

First you need to configure your business schedule:

…

Methods

within() - Tells if a date is within business hours
php
$bool = $business->within(new \DateTime('2015-05-11 10:00'));
timeline() - Returns a timeline of business dates
php
$start = new \DateTime('2015-05-11 10:00');
$end = new \DateTime('2015-05-14 10:00');
$interval = new \DateInterval('P1D');

$dates = $business->timeline($start, $end, $interval);
closest() - Returns the closest business date from a given date
php
// After that date (including it)
$nextDate = $business->closest(new \DateTime('2015-05-11 10:00'));

// Before that date (including it)
$lastDate = $business->closest(new \DateTime('2015-05-11 10:00'), Business::CLOSEST_LAST);

Serialization

PHP serialization

The Business class can be serialized so it can be stored for later reuse:

php
$serialized = serialize($business);
$business = unserialize($serialized);

If you use SpecialDay instances, you need to install the jeremeamia/superclosure library providing closure serialization:

bash
$ composer require jeremeamia/superclosure

JSON serialization

All classes can be encoded to JSON

php
$json = json_encode($business);

The SpecialDay instances require a context in order extract the data from the callable. This is automatically set to new \DateTime('now') for json_encode() call only.

License

MIT

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPbusiness-hoursdateopening-hoursphp

No comments yet. Be the first to share.

> Details

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

> Related tools

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