This library allow to manage datetime recurrences. It implement basic RRULE standards and add constraints support.
RFC : https://tools.ietf.org/html/rfc5545#page-37
$recurrence = (new Recurrence())
->setFrequency(new Frequency('MONTHLY'))
->setPeriodStartAt(new \Datetime('2017-01-01'))
->setPeriodEndAt(new \Datetime('2017-12-31'))
->setInterval(1);
$periods = (new DatetimeProvider())->provide($recurrence);Available methods :
setFrequency(Frequency) : setFREQoptionsetPeriodStartAt(\Datetime()) : setDTSTARToptionsetPeriodEndAt(\Datetime()) : setUNTILoptionsetInterval(integer) : setINTERVALoptionsetCount(integer) : setCOUNToption
This example as the same result as example above using object method :
$recurrence = (new RecurrenceProvider())->create('FREQ=MONTHLY;DTSTART=20170101;UNTIL=20171231;INTERVAL=1');
$periods = (new DatetimeProvider())->provide($recurrence);Supported rules :
FREQ:YEARLY,MONTHLY,WEEKLY,DAILY,HOURLY,MINUTELY,SECONDLYDTSTART:- Simple date :
stringusing formatYYYYMMDD(example :20170520) - Datetime :
stringusing formatYYYYMMDDTHHMMSS(example :20170520T154720) - Datetime UTC :
stringusing formatYYYYMMDDTHHMMSSZ(example :20170520T154720Z)
- Simple date :
DTSTARTwithTZID:stringusing format{timezone}:YYYYMMDDTHHMMSS(example :Europe/Paris:20170520T154720)UNTIL:- Simple date :
stringusing formatYYYYMMDD(example :20170520) - Datetime :
stringusing formatYYYYMMDDTHHMMSS(example :20170520T154720) - Datetime UTC :
stringusing formatYYYYMMDDTHHMMSSZ(example :20170520T154720Z)
- Simple date :
UNTILwithTZID:stringusing format{timezone}:YYYYMMDDTHHMMSS(example :Europe/Paris:20170520T154720)INTERVAL: simpleintegerCOUNT: simpleinteger
You can add some constraint to Recurrence in order to manage more precisely generated datetimes.
For example, if you do not want to generate datetime on wednesday (day 3 according to date format in PHP), add this constraint :
$recurrence->addConstraint(new ExcludeDaysOfWeekConstraint([3]));EndOfMonthConstraint: if recurrence hasMONTHLYfrequency and start date is last day of current month, force last day of month for all datetimesExcludeDaysOfWeekConstraint: if datetime is concerned,DatetimeProviderwill return next valid dateExcludeWeekendConstraint: if datetime is concerned,DatetimeProviderwill return next monday
Constraints are not a part of RRULE standard, this is an addition to optimize datetimes manipulation.
Be careful, constraints will be applied in the order you add it to recurrence.
./vendor/bin/atoum -d tests/units/Recurrence
Html code coverage is generated here : ./var/code-coverage
Remember that you need xdebug to generate code coverage report.
To assume that you don't degrade performance when you update the library, run a benchmark using context name initial first :
./vendor/bin/phpbench run --store --tag="initial" --report=default
Before committing your changes, run a new benchmark using update as context :
./vendor/bin/phpbench run --store --tag="update" --report=default
You can then list log to see evolution using :
./vendor/bin/phpbench log
Or even better, compare the 2 benchmarks and see if you don't degrade performance with your changes :
./vendor/bin/phpbench run --report=aggregate --ref=initial

