cog/chrono-shifter
最新稳定版本:2.3
Composer 安装命令:
composer require cog/chrono-shifter
包简介
PHP iterators for moving around in time
README 文档
README
ChronoShifter
PHP framework for navigating through time using the Gregorian calendar.
Contents
Shifters
Shifters transform time.
use COG\ChronoShifter\Direction\Increasing;
use COG\ChronoShifter\Period\Month;
use COG\ChronoShifter\Selector\Specific;
use COG\ChronoShifter\Shifter\ChronoShifter;
$shifter = new ChronoShifter(new Month('2015-01-05'), new Specific(new Increasing(), 5));
$shifter->next('2015-01-05'); // '2015-02-05'
Shifters are designed to be composable and extendible. The number of combinations they can be used in is high, and it is fairly simple to create new shifters, directions, periods, and selectors.
There are more shifters available to combine or alter the results.
Periods
Periods encapsulate the logic how to traverse between periods. Periods are commonly used for answering questions such as "When is the first Friday of this month?"
use COG\ChronoShifter\Period\Month;
$month = new Month('2015-01-12');
$month->getStartDate(); // '2015-12-01'
$month->getEndDate(); // '2015-12-31'
$month->next();
$month->getStartDate(); // '2015-01-01'
$month->getEndDate(); // '2015-01-31'
IsoChronic period represents an evenly divided period of time.
use COG\ChronoShifter\Period\IsoChronic;
$iso = new IsoChronic('2015-01-11', '2015-01-11', 7);
$iso->getStartDate(); // '2015-01-11'
$iso->getEndDate(); // '2015-01-17'
$iso->next();
$iso->getStartDate(); // '2015-01-18'
$iso->getEndDate(); // '2015-01-24'
Evaluators
Evaluators encapsulate facts about dates.
use COG\ChronoShifter\Evaluator\DayOfWeek;
$evaluator = new DayOfWeek(DayOfWeek::MONDAY);
$evaluator->is('2015-01-24'); // False
There are 5 evalutors for basic facts about dates, and logical evaluators AND/OR/NOT to support combining the evaluators however necessary:
DayOfWeek($dayOfWeek : int)Holiday($holidayProvider : HolidayProvider);Weekday();Weekend();Workday($holidayProvider : HolidayProvider);LogicalAnd($first : Evaluator, $second : Evaluator);LogicalOr($first : Evaluator, $second : Evaluator);LogicalNot($evaluator : Evaluator);
Selectors
Selectors use a period, direction and evaluator to find a match.
FirstOf($direction : Direction, $evaluator : Evaluator);LastOf($direction : Direction, $evaluator : Evaluator);Specific($direction : Direction, $number : int);
Directions
Directions specify how to traverse between periods. There are two supplied with ChronoShifter: increment to future or decrement to past.
Increasing();Decreasing();
HolidayProvider
There are many ways how to represent holidays, and ChronoShifter provides an interface, so you can plug in your application's holiday logic.
use COG\ChronoShifter\HolidayProvider\ArrayHolidayProvider;
$holidayProvider = new ArrayHolidayProvider(array('2015-01-01'));
$holidayProvider->isHoliday('2014-12-31'); // False
$holidayProvider->isHoliday('2015-01-01'); // True
Examples
- Day of Month, Increment
- Day of Month, Decrement
- Isochronic (7d), Increment
- Isochronic (7d), Decrement
- Isochronic (14d), Increment
- Isochronic (14d), Decrement
- Monthly First Day of Week, Increment
- Monthly First Day of Week, Decrement
- Monthly Last Day of Week, Increment
- Monthly Last Day of Week, Decrement
- Monthly First Workday, Increment
- Monthly First Workday, Decrement
- Monthly Last Workday, Increment
- Monthly Last Workday, Decrement
cog/chrono-shifter 适用场景与选型建议
cog/chrono-shifter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 52.4k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 03 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「iterator」 「time」 「date」 「period」 「recurring」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cog/chrono-shifter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cog/chrono-shifter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cog/chrono-shifter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
collection php library
Tools to convert between .NET and PHP date formats
PHP PDO Mysql select statement iterator implemented as multiple queries using LIMIT clauses
Adds the EDTF data type to Wikibase
Iteration tools for PHP
统计信息
- 总下载量: 52.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-31