jupitern / scheduler
php event schedule
1.3.1
2016-12-16 12:08 UTC
Requires
- php: >=5.4
README
jupitern/scheduler
PHP Scheduler.
add one time event dates or recurring event dates get next event date or next X event dates from a given date
Requirements
PHP 5.4 or higher.
Installation
Include jupitern/scheduler in your project, by adding it to your composer.json file.
{ "require": { "jupitern/scheduler": "1.*" } }
Usage
// instance Scheduler $schedules = \Jupitern\Scheduler\Scheduler::instance() // limit events from 08.00 am to 17.00 ->setTimeFrame('08:00', '17:00') // add a one time event date // accepts any string compatible with php DateTime object ->add('2020-01-01 12:35') // add another one time event date // accepts any string compatible with php DateTime object ->add('2020-01-01 17:50') // add a recurring date // accepts any string compatible with php DateTime object ->addRecurring('+ 8 hours') // get next schedule starting at 2020-01-01 ->getNextSchedule('2020-01-01 00:00:00', 10); // get next 5 schedules starting at 2020-01-01 ->getNextSchedules('2020-01-01 00:00:00', 10); // display schedules foreach ($schedules as $schedule) { echo $schedule->format('Y-m-d H:i')."<br/>"; }
Examples
$schedules = \Jupitern\Scheduler\Scheduler::instance() ->add('2030-01-01 12:35') ->add('2030-01-01 14:50') ->addRecurring('+2 hours') ->getNextSchedules('2030-01-01 00:00:00', 10); foreach ($schedules as $schedule) { echo $schedule->format('Y-m-d H:i').'<br/>'; } /* output: 2030-01-01 00:00 2030-01-01 02:00 2030-01-01 04:00 2030-01-01 06:00 2030-01-01 08:00 2030-01-01 10:00 2030-01-01 12:00 2030-01-01 12:35 2030-01-01 14:00 2030-01-01 14:50 */ $schedules = \Jupitern\Scheduler\Scheduler::instance() ->setTimeFrame('08:00', '17:00') ->add('2030-01-01 12:35') ->add('2030-01-01 14:50') ->addRecurring('+2 hours') ->getNextSchedules('2030-01-01 00:00:00', 10); foreach ($schedules as $schedule) { echo $schedule->format('Y-m-d H:i').'<br/>'; } /* output: 2030-01-01 08:00 2030-01-01 10:00 2030-01-01 12:00 2030-01-01 12:35 2030-01-01 14:00 2030-01-01 14:50 2030-01-01 16:00 2030-01-02 08:00 2030-01-02 10:00 2030-01-02 12:00 */ $schedules = \Jupitern\Scheduler\Scheduler::instance() ->setTimeFrame('08:30', '19:00') ->add('+10 minutes') ->add('+30 minutes') // outside time frame. will not produce any schedule ->add('next day 08:30') ->getNextSchedules('2000-12-16 18:40'); foreach ($schedules as $schedule) { echo $schedule->format('Y-m-d H:i')."<br/>"; } /* output: 2000-12-16 18:50 2000-12-17 08:30 */
ChangeLog
v1.3
- Changed method add to allow relative one time events like "+1 hour" or "next day 17:00"
- relative events added with method add() are relative to $fromStartDate and obey time frame if set
Contributing
- welcome to discuss a bugs, features and ideas.
License
jupitern/scheduler is release under the MIT license.
You are free to use, modify and distribute this software