定制 cog/chrono-shifter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cog/chrono-shifter

最新稳定版本:2.3

Composer 安装命令:

composer require cog/chrono-shifter

包简介

PHP iterators for moving around in time

README 文档

README

Build Status Code Coverage Scrutinizer Code Quality

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

统计信息

  • 总下载量: 52.4k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 27
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-31