Scheduler
PHP Simple Scheduler - set occurrence expressions and get next x execution dates [Cron, Crontab, Task Scheduler]
Install / Use
/learn @jupitern/SchedulerREADME
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.
{
"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.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
Related Skills
node-connect
347.6kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.6kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.6kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。


