HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
CronExpression Class Reference

Public Member Functions

 __construct ($expression, FieldFactory $fieldFactory)
 setExpression ($value)
 setPart ($position, $value)
 getNextRunDate ($currentTime= 'now', $nth=0, $allowCurrentDate=false)
 getPreviousRunDate ($currentTime= 'now', $nth=0, $allowCurrentDate=false)
 getMultipleRunDates ($total, $currentTime= 'now', $invert=false, $allowCurrentDate=false)
 getExpression ($part=null)
 __toString ()
 isDue ($currentTime=null)

Static Public Member Functions

static factory ($expression, FieldFactory $fieldFactory=null)

Public Attributes

const MINUTE = 0
const HOUR = 1
const DAY = 2
const MONTH = 3
const WEEKDAY = 4
const YEAR = 5

Protected Member Functions

 getRunDate ($currentTime=null, $nth=0, $invert=false, $allowCurrentDate=false)

Private Attributes

 $cronParts
 $fieldFactory

Static Private Attributes

static $order = array(self::YEAR, self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE)

Detailed Description

CRON expression parser that can determine whether or not a CRON expression is due to run, the next run date and previous run date of a CRON expression. The determinations made by this class are accurate if checked run once per minute (seconds are dropped from date time comparisons).

Schedule parts must map to: minute [0-59], hour [0-23], day of month, month [1-12|JAN-DEC], day of week [1-7|MON-SUN], and an optional year.

Author
Michael Dowling mtdow.nosp@m.ling.nosp@m.@gmai.nosp@m.l.co.nosp@m.m

http://en.wikipedia.org/wiki/Cron

Definition at line 17 of file CronExpression.php.

Constructor & Destructor Documentation

CronExpression::__construct (   $expression,
FieldFactory  $fieldFactory 
)

Parse a CRON expression.

Parameters
string$expressionCRON expression (e.g. '8 * * * *')
FieldFactory$fieldFactoryFactory to create cron fields

Definition at line 82 of file CronExpression.php.

Here is the call graph for this function:

Member Function Documentation

CronExpression::__toString ( )

Helper method to output the full expression.

Returns
string Full CRON expression

Definition at line 223 of file CronExpression.php.

Here is the call graph for this function:

FieldFactory CRON field CronExpression::factory (   $expression,
FieldFactory  $fieldFactory = null 
)
static

Factory method to create a new CronExpression.

Parameters
string$expressionThe CRON expression to create. There are several special predefined values which can be used to substitute the CRON expression:

, ) - Run once a year, midnight, Jan. 1 - 0 0 1 1 * - Run once a month, midnight, first of month - 0 0 1 * * - Run once a week, midnight on Sun - 0 0 * * 0 - Run once a day, midnight - 0 0 * * * - Run once an hour, first minute - 0 * * * *

Parameters
FieldFactory$fieldFactory(optional) Field factory to use
Returns
CronExpression

Definition at line 58 of file CronExpression.php.

Here is the caller graph for this function:

CronExpression::getExpression (   $part = null)

Get all or part of the CRON expression.

Parameters
string$part(optional) Specify the part to retrieve or NULL to get the full cron schedule string.
Returns
string|null Returns the CRON expression, a part of the CRON expression, or NULL if the part was specified but not found

Definition at line 207 of file CronExpression.php.

Here is the caller graph for this function:

CronExpression::getMultipleRunDates (   $total,
  $currentTime = 'now',
  $invert = false,
  $allowCurrentDate = false 
)

Get multiple run dates starting at the current date or a specific date.

Parameters
int$totalSet the total number of dates to calculate
string | DateTime$currentTime(optional) Relative calculation date
bool$invert(optional) Set to TRUE to retrieve previous dates
bool$allowCurrentDate(optional) Set to TRUE to return the current date if it matches the cron expression
Returns
array Returns an array of run dates

Definition at line 188 of file CronExpression.php.

Here is the call graph for this function:

CronExpression::getNextRunDate (   $currentTime = 'now',
  $nth = 0,
  $allowCurrentDate = false 
)

Get a next run date relative to the current date or a specific date.

Parameters
string | DateTime$currentTime(optional) Relative calculation date
int$nth(optional) Number of matches to skip before returning a matching next run date. 0, the default, will return the current date and time if the next run date falls on the current date and time. Setting this value to 1 will skip the first match and go to the second match. Setting this value to 2 will skip the first 2 matches and so on.
bool$allowCurrentDate(optional) Set to TRUE to return the current date if it matches the cron expression
Returns
DateTime
Exceptions
RuntimeExpressionon too many iterations

Definition at line 153 of file CronExpression.php.

Here is the call graph for this function:

Here is the caller graph for this function:

CronExpression::getPreviousRunDate (   $currentTime = 'now',
  $nth = 0,
  $allowCurrentDate = false 
)

Get a previous run date relative to the current date or a specific date.

Parameters
string | DateTime$currentTime(optional) Relative calculation date
int$nth(optional) Number of matches to skip before returning
bool$allowCurrentDate(optional) Set to TRUE to return the current date if it matches the cron expression
Returns
DateTime
Exceptions
RuntimeExpressionon too many iterations
See Also
Cron::getNextRunDate

Definition at line 172 of file CronExpression.php.

Here is the call graph for this function:

CronExpression::getRunDate (   $currentTime = null,
  $nth = 0,
  $invert = false,
  $allowCurrentDate = false 
)
protected

Get the next or previous run date of the expression relative to a date.

Parameters
string | DateTime$currentTime(optional) Relative calculation date
int$nth(optional) Number of matches to skip before returning
bool$invert(optional) Set to TRUE to go backwards in time
bool$allowCurrentDate(optional) Set to TRUE to return the current date if it matches the cron expression
Returns
DateTime
Exceptions
RuntimeExpressionon too many iterations

Definition at line 268 of file CronExpression.php.

Here is the call graph for this function:

Here is the caller graph for this function:

CronExpression::isDue (   $currentTime = null)

Deterime if the cron is due to run based on the current date or a specific date. This method assumes that the current number of seconds are irrelevant, and should be called once per minute.

Parameters
string | DateTime$currentTime(optional) Relative calculation date
Returns
bool Returns TRUE if the cron is due to run or FALSE if not

Definition at line 237 of file CronExpression.php.

Here is the call graph for this function:

CronExpression::setExpression (   $value)

Set or change the CRON expression.

Parameters
string$scheduleCRON expression (e.g. 8 * * * *)
Returns
CronExpression
Exceptions
InvalidArgumentExceptionif not a valid CRON expression

Definition at line 97 of file CronExpression.php.

Here is the call graph for this function:

Here is the caller graph for this function:

CronExpression::setPart (   $position,
  $value 
)

Set part of the CRON expression.

Parameters
int$positionThe position of the CRON expression to set
string$valueThe value to set
Returns
CronExpression
Exceptions
InvalidArgumentExceptionif the value is not valid for the part

Definition at line 123 of file CronExpression.php.

Here is the caller graph for this function:

Member Data Documentation

CronExpression::$cronParts
private

Definition at line 29 of file CronExpression.php.

CronExpression::$fieldFactory
private

Definition at line 34 of file CronExpression.php.

CronExpression::$order = array(self::YEAR, self::MONTH, self::DAY, self::WEEKDAY, self::HOUR, self::MINUTE)
staticprivate

Definition at line 39 of file CronExpression.php.

const CronExpression::DAY = 2

Definition at line 21 of file CronExpression.php.

const CronExpression::HOUR = 1

Definition at line 20 of file CronExpression.php.

const CronExpression::MINUTE = 0

Definition at line 19 of file CronExpression.php.

const CronExpression::MONTH = 3

Definition at line 22 of file CronExpression.php.

const CronExpression::WEEKDAY = 4

Definition at line 23 of file CronExpression.php.

const CronExpression::YEAR = 5

Definition at line 24 of file CronExpression.php.


The documentation for this class was generated from the following file: