https://github.com/jupitern/scheduler
PHP Simple Scheduler - set occurrence expressions and get next x execution dates [Cron, Crontab, Task Scheduler]
https://github.com/jupitern/scheduler
php recurring-events schedule
Last synced: about 1 year ago
JSON representation
PHP Simple Scheduler - set occurrence expressions and get next x execution dates [Cron, Crontab, Task Scheduler]
- Host: GitHub
- URL: https://github.com/jupitern/scheduler
- Owner: jupitern
- License: mit
- Created: 2015-06-22T14:58:14.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2024-12-05T15:05:53.000Z (over 1 year ago)
- Last Synced: 2025-04-22T20:16:44.838Z (about 1 year ago)
- Topics: php, recurring-events, schedule
- Language: PHP
- Homepage:
- Size: 14.6 KB
- Stars: 23
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://scrutinizer-ci.com/g/jupitern/Scheduler/build-status/master)
[](https://scrutinizer-ci.com/g/jupitern/Scheduler/?branch=master)
[](https://packagist.org/packages/jupitern/scheduler)
[](https://packagist.org/packages/jupitern/scheduler)
[](https://packagist.org/packages/jupitern/scheduler)
# 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 8.0 or higher.
## Installation
Include jupitern/scheduler in your project, by adding it to your composer.json file.
```javascript
{
"require": {
"jupitern/scheduler": "1.*"
}
}
```
## Usage
```php
// 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')."
";
}
```
## Examples
```php
$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').'
';
}
/*
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').'
';
}
/*
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')."
";
}
/*
output:
2000-12-16 18:50
2000-12-17 08:30
*/
```
## ChangeLog
v1.4
- min php version updated to 8.0
- code refactor for php 8
- bug fix to avoid duplicate dates when calculated dates from different schedules match
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