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
统计信息
- 总下载量: 52.4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-31