cog / chrono-shifter
PHP iterators for moving around in time
Installs: 52 401
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 27
Forks: 0
Open Issues: 0
Requires
- php: >= 5.5
Requires (Dev)
- instaclick/php-code-sniffer: 1.4.*
- pdepend/pdepend: 2.0.*
- phploc/phploc: 2.1.*
- phpmd/phpmd: 2.2.*
- phpunit/phpunit: 4.5.*
- sebastian/phpcpd: 2.0.*
- theseer/phpdox: 0.7.*
This package is not auto-updated.
Last update: 2021-11-30 19:08:58 UTC
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