Release Schedule Helper
- Tags: php,
- Written on: August 1, 2013
I release a library to help with generating re-occuring schedules. Lacking a better name I called it ScheduleHelper.
I worked on this code for 3 afternoons, I developed this component as part of a future bill reminder app for owncloud.
I used a builder to hide the complexity of configuring a schedule and standardize the return type to an Iterator, you may ask the builder to skip the iterator ahead while skipping the start to simulate end of period billing and I have implement the following common periods, Yearly, Weekly, Monthly, Fortnightly, Weekday, BiMonthly, Quarterly.
Examples
This create a daily schedule that limit to 12 re-occursions and skip the first period. Important to note that there will be 13 occurrences, if the start is not skipped. This is a feature of PHP DatePeriod when setting a limit using an integer
use DateTime; use IComeFromTheNet\Schedule\ScheduleBuilder; $start = new DateTime(); $occurrence = 12; $builder = new ScheduleBuilder(); return $builder->daily() ->start($start) ->limit($reoccurance) ->skipStart() ->build();
This will return a monthly schedule 4 occurances in. If the starting month was August the first starting value at december. Using a LimitIterator to restrict the result set.
use DateTime; use IComeFromTheNet\Schedule\ScheduleBuilder; $start = new DateTime(); $reoccurance = 12; $builder = new ScheduleBuilder(); return $builder->monthly() ->start($start) ->limit($reoccurance) ->offset(4) ->build();
This will return a monthly schedule, the rule is defined using a string and not direct method call.
use DateTime; use IComeFromTheNet\Schedule\ScheduleBuilder; $start = new DateTime(); $reoccurance = 12; $builder = new ScheduleBuilder(); return $builder->create('monthly') ->start($start) ->limit($reoccurance) ->build();