florianv/business
Composer 安装命令:
composer require florianv/business
包简介
DateTime calculations in business hours
README 文档
README
DateTime calculations in business hours
Installation
$ composer require florianv/business
Usage
First you need to configure your business schedule:
use Business\SpecialDay; use Business\Day; use Business\Days; use Business\Business; use Business\Holidays; use Business\DateRange; // Opening hours for each week day. If not specified, it is considered closed $days = [ // Standard days with fixed opening hours new Day(Days::MONDAY, [['09:00', '13:00'], ['2pm', '5 PM']]), new Day(Days::TUESDAY, [['9 AM', '5 PM']]), new Day(Days::WEDNESDAY, [['10:00', '13:00'], ['14:00', '17:00']]), new Day(Days::THURSDAY, [['10 AM', '5 PM']]), // Special day with dynamic opening hours depending on the date new SpecialDay(Days::FRIDAY, function (\DateTime $date) { if ('2015-05-29' === $date->format('Y-m-d')) { return [['9 AM', '12:00']]; } return [['9 AM', '5 PM']]; }), ]; // Optional holiday dates $holidays = new Holidays([ new \DateTime('2015-01-01'), new \DateTime('2015-01-02'), new DateRange(new \DateTime('2015-07-08'), new \DateTime('2015-07-11')), ]); // Optional business timezone $timezone = new \DateTimeZone('Europe/Paris'); // Create a new Business instance $business = new Business($days, $holidays, $timezone);
Methods
within() - Tells if a date is within business hours
$bool = $business->within(new \DateTime('2015-05-11 10:00'));
timeline() - Returns a timeline of business dates
$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
// 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:
$serialized = serialize($business); $business = unserialize($serialized);
If you use SpecialDay instances, you need to install the jeremeamia/superclosure library providing closure serialization:
$ composer require jeremeamia/superclosure
JSON serialization
All classes can be encoded to JSON
$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
florianv/business 适用场景与选型建议
florianv/business 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 782.47k 次下载、GitHub Stars 达 360, 最近一次更新时间为 2015 年 05 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「time」 「date」 「schedule」 「business」 「hour」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 florianv/business 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 florianv/business 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 florianv/business 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Tools to convert between .NET and PHP date formats
Enables the creation of cron-jobs tasks to be consumed by symfony/messenger
Adds the EDTF data type to Wikibase
A Deployment/Change Log Schedule and Notes system for SilverStripe sites
A powerful event calendar Tool for Laravel's Nova 5.
Date component is a set of methods to help with the manipulation of dates.
统计信息
- 总下载量: 782.47k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 362
- 点击次数: 31
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-25