Cron
Cron
This class can be used to parse cron strings and compute schedules.
It can parse a given string with a schedule specification in cron format. The class can compute the last and the next schedule times relative to a given time.
Example
$cron = new \Hazaar\Cron('0,30 9-17 \* \* 1-5');
$next = $cron->getNextOccurrence();
This will get the next occurrence from the schedule which should return dates and times for every 0th and 30th minute between 9am and 5pm, Monday to Friday.
Properties
ranges
Ranges.
private $ranges
intervals
Named intervals.
private $intervals
keywords
Possible keywords for months/weekdays.
private $keywords
pcron
public int $pcron
Methods
__construct
Creates a new instance of the Cron class.
public __construct({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$expression | string | The CRON expression to parse |
getNextOccurrence
Calculates the next time and date based on the supplied expression.
public getNextOccurrence({Array})
If a reference-time is passed, the next time and date after that time is calculated.
Parameters
Parameter | Type | Description |
---|---|---|
$timestamp | int | optional reference-time |
getLastOccurrence
Calculates the last time and date before the supplied expression.
public getLastOccurrence({Array})
If a reference-time is passed, the last time and date before that time is calculated.
Parameters
Parameter | Type | Description |
---|---|---|
$timestamp | int | optional reference-time |
calculateDateTime
Calculates the time and date at which the next/last call of a cronjob is/was due.
private calculateDateTime({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$rtime | array | reference-time |
$next | bool | true = nextOccurence, false = lastOccurence |
getTimestamp
Converts an unix-timestamp to an array.
private getTimestamp({Array})
The returned array contains the following values:
[0] -> minute [1] -> hour [2] -> day [3] -> month [4] -> weekday [5] -> year
The array is used by various functions.
Parameters
Parameter | Type | Description |
---|---|---|
$timestamp | int | If none is given, the current time is used |
findValue
Checks if the given value exists in an array.
private findValue({Array})
If it does not exist, the next higher/lower value is returned (depending on $next). If no higher/lower value exists, false is returned.
Parameters
Parameter | Type | Description |
---|---|---|
$value | int | |
$data | mixed | |
$next | boolean |
arrayReverse
Reverses all sub-arrays of our cron array.
private arrayReverse({Array})
The reversed values are used for calculations that are run when getLastOccurence() is called.
Parameters
Parameter | Type | Description |
---|---|---|
$cron | array |
parse
Analyses crontab-expressions like "* * 1,2,3 * mon,tue" and returns an array containing all values.
private parse({Array})
If it can not be parsed then it returns FALSE
Parameters
Parameter | Type | Description |
---|---|---|
$expression | string | the cron-expression to parse |
expandSegment
Analyses a single segment.
private expandSegment({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$idx | int | |
$segment | string | |
$ | false |
parseAtom
Analyses a single segment.
private parseAtom({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$atom | string | The segment to parse |
Generated by Hazaar API Doc Generator