\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
Methods Properties Constants
No constants
Properties
$intervals
$intervals
Named intervals.
$keywords
$keywords
Possible keywords for months/weekdays.
$pcron
$pcron
$ranges
$ranges
Ranges.
Methods
__construct()
__construct($expression)

Parameters

$expression

No description

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.

Parameters

$cronmixed

No description

Returns

Array
calculateDateTime()
calculateDateTime($rtime, $next = true) : int
Calculates the time and date at which the next/last call of a cronjob is/was due.

Parameters

$rtimemixed

reference-time

$next\Hazaar\bool

true = nextOccurence, false = lastOccurence

Returns

int
expandSegment()
expandSegment($idx, $segment) : mixed
Analyses a single segment

Parameters

$idxint

No description

$segmentstring

No description

Returns

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

Parameters

$valueint

No description

$datamixed

No description

$next\Hazaar\bool

No description

Returns

mixed

The next value or false if there isn’t one.

getLastOccurrence()
getLastOccurrence($timestamp = null) : int
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.

Parameters

$timestampint

optional reference-time

Returns

int
getNextOccurrence()
getNextOccurrence($timestamp = null) : int
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.

Parameters

$timestampint

optional reference-time

Returns

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

Parameters

$timestampint

If none is given, the current time is used

Returns

Array
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

Parameters

$expressionstring

The cron-expression to parse.

Returns

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

Parameters

$atomstring

The segment to parse

Returns

array