Download the PHP package nephifey/cron-expression without Composer
On this page you can find all versions of the php package nephifey/cron-expression. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nephifey/cron-expression
More information about nephifey/cron-expression
Files in nephifey/cron-expression
Package cron-expression
Short Description Cron expression parser to get the previous run date, next run date, and determine if the expression is due to run based on the next run date.
License GPL-3.0-or-later
Homepage https://github.com/nephifey/cron-expression
Informations about the package cron-expression
cron-expression
Cron expression parser to get the previous run date, next run date, and determine if the expression is due to run based on the next run date. This implementation supports the minute, hour, day of the month, month, and day of the week attributes and only supports a limited amount of non-standard characters/macros, see the Cron Expression Format below.
Cron Expression Format:
Refer to the Cron Wikipedia Page if desired, which is where most this content is from, but keep in mind this library doesn't support everything documented within there.
Supported Characters:
Character | Description | Example Expression | |
---|---|---|---|
Asterisk * |
Equivalent to "all" or the entire allowed range of values. | * * * * * |
|
Comma , |
Comma separated value list for scheduling multiple different times. | 3,57 * * * SUN,MON |
|
Hyphen - |
Used to specify a range of values for scheduling multiple different times. | * * * * TUE-SAT |
|
Slash / |
Used to specify stepped values throughout the allowed range of values. | */5 * * * * |
|
Numeric (or) Non-standard Literal | Schedule using a specific number within the allowed range of values. | 5 * * * * |
Supported Non-standard Literals:
Attribute | Literal | Mapped Numeric |
---|---|---|
month | JAN | 1 |
month | FEB | 2 |
month | MAR | 3 |
month | APR | 4 |
month | MAY | 5 |
month | JUN | 6 |
month | JUL | 7 |
month | AUG | 8 |
month | SEP | 9 |
month | OCT | 10 |
month | NOV | 11 |
month | DEC | 12 |
day of the week | SUN | 0 |
day of the week | MON | 1 |
day of the week | TUE | 2 |
day of the week | WED | 3 |
day of the week | THU | 4 |
day of the week | FRI | 5 |
day of the week | SAT | 6 |
day of the week | 7 | 0 |
Supported Non-standard Macros:
Macro | Description | Mapped Expression |
---|---|---|
@yearly |
Run once a year at midnight of 1 January | 0 0 1 1 * |
@annually |
Run once a year at midnight of 1 January | 0 0 1 1 * |
@monthly |
Run once a month at midnight of the first day of the month | 0 0 1 1 * |
@weekly |
Run once a week at midnight on Sunday | 0 0 1 1 * |
@daily |
Run once a day at midnight | 0 0 1 1 * |
@midnight |
Run once a day at midnight | 0 0 1 1 * |
@hourly |
Run once an hour at the beginning of the hour | 0 0 1 1 * |
Getting Started
Install the package into your project using composer via the command below.
Usage
Basic Example
Parse cron expressions and get the previous run date, next run date, or check if the expression is due.
Scheduler Example
Use as a crontab alternative to keep expressions within the codebase or database.
Crontab Setup:
Codebase Setup:
Additional Examples
You can pass a custom datetime to the isDue method instead of the current datetime/timezone. Additionally, you can enable strict mode, so then it must match the exact datetime/timezone.
You can reparse cron expressions directly on the expression object based on a new datetime/timezone later on. This can be done in a mutable or immutable way depending on your need.