boldgrid/tdcron

A simple utility to manipulate cron jobs.

1.0.0 2022-11-02 14:18 UTC

This package is auto-updated.

Last update: 2024-05-13 17:52:00 UTC


README

WARNING: This class was written back in 2010 ! Its pretty much untested with all PHP versions > 5.6.0 and might act funny. I mostly pushed it to GitHub for easier access and in case if somebody is looking for a simple cron-parser.

tdCron

tdCron is a very simple class to parse cron-expressions and calculate schedules.

For something more sophisticated (and WAY more modern) you can take a look at the cron-expression package by Michael Dowling and Chris Tankersley.

Getting Started

Installation

Just include class.tdcron.php and class.tdcron.entry.php in your project and you're done.

Documentation

As i mentioned before - this class is really, really simple :-)

Please just look at the code in test.php and class.tdcron.php - its reasonably well documented and should be pretty easy to understand.

It basically comes down to calling tdCron::getNextOccurrence() or tdCron::getLastOccurrence() with your cron-expression as the first parameter and an optional reference-time as the second parameter.

Lets say you've got a cron-expression like 5 0 * 8 2 (so something at 00:05 on every tuesday in august). You could use something like

echo 'next: '.date('d.m.Y, H:i:s', tdCron::getNextOccurrence('5 0 * 8 2');

to see when it should run the next time.

Running the tests

There aren't any "real" tests included with the class (so you won't find any PHPUnit-stuff here). You can find a bunch of edge-cases in the test.php / test.data.php files that were used to test the class during development.

License

This project is licensed under the MIT License - see the LICENSE file for details