Hazaar
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.

Summary
MethodsPropertiesConstants
No constants
Properties
$intervals
$intervals
Named intervals.
$keywords
$keywords
Possible keywords for months/weekdays.
$pcron
$pcron
$ranges
$ranges
Ranges.
Methods
__construct()
__construct($expression)
arrayReverse()
arrayReverse($cron) : Array
Reverses all sub-arrays of our cron array.

The reversed values are used for calculations that are run when getLastOccurence() is called.

calculateDateTime()
calculateDateTime($rtime, $next = true) : int|null
Calculates the time and date at which the next/last call of a cronjob is/was due.
expandSegment()
expandSegment($idx, $segment) : mixed
Analyses a single segment
findValue()
findValue($value, $data, $next = true) : mixed
Checks if the given value exists in an 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.

getLastOccurrence()
getLastOccurrence($timestamp = null) : int|null
Calculates the last time and date before the supplied expression.

If a reference-time is passed, the last time and date before that time is calculated.

getNextOccurrence()
getNextOccurrence($timestamp = null) : int|null
Calculates the next time and date based on the supplied expression.

If a reference-time is passed, the next time and date after that time is calculated.

getTimestamp()
getTimestamp($timestamp = null) : Array
Converts an unix-timestamp to an 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.

parse()
parse($expression) : mixed
Analyses crontab-expressions like "* * 1,2,3 * mon,tue" and returns an array containing all values.

If it can not be parsed then it returns FALSE

parseAtom()
parseAtom($atom) : array
Analyses a single segment