TYPO3  7.6
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CronCommand Class Reference

Public Member Functions

 __construct ($cronCommand, $timestamp=false)
 
 calculateNextValue ()
 
 getTimestamp ()
 
 getCronCommandSections ()
 

Protected Member Functions

 minuteAndHourMatchesCronCommand ($timestamp)
 
 dayMatchesCronCommand ($timestamp)
 
 isInCommandList ($commandExpression, $numberToMatch)
 
 numberOfSecondsInDay ($timestamp)
 
 roundTimestamp ($timestamp)
 

Protected Attributes

 $cronCommandSections
 
 $timestamp
 

Detailed Description

This class provides calculations for the cron command format.

Definition at line 20 of file CronCommand.php.

Constructor & Destructor Documentation

__construct (   $cronCommand,
  $timestamp = false 
)

Constructor

Parameters
string$cronCommandThe cron command can hold any combination documented as valid
bool | int$timestampOptional start time, used in unit tests
Returns

Definition at line 54 of file CronCommand.php.

References CronCommand\$timestamp, NormalizeCommand\normalize(), and CronCommand\roundTimestamp().

Member Function Documentation

calculateNextValue ( )

Calculates the date of the next execution.

Returns
void
Exceptions
\RuntimeException

Definition at line 76 of file CronCommand.php.

References CronCommand\dayMatchesCronCommand(), CronCommand\getTimestamp(), CronCommand\minuteAndHourMatchesCronCommand(), and CronCommand\numberOfSecondsInDay().

dayMatchesCronCommand (   $timestamp)
protected

Determine if current timestamp matches day of month, month and day of week cron command restriction

Parameters
int$timestampto test
Returns
bool TRUE if cron command conditions are met

Definition at line 156 of file CronCommand.php.

References CronCommand\$timestamp, and CronCommand\isInCommandList().

Referenced by CronCommand\calculateNextValue().

getCronCommandSections ( )

Get cron command sections. Array of strings, each containing either a list of comma separated integers or *

Returns
array command sections:

Definition at line 127 of file CronCommand.php.

References CronCommand\$cronCommandSections.

getTimestamp ( )

Get next timestamp

Returns
int Unix timestamp

Definition at line 116 of file CronCommand.php.

References CronCommand\$timestamp.

Referenced by CronCommand\calculateNextValue().

isInCommandList (   $commandExpression,
  $numberToMatch 
)
protected

Determine if a given number validates a cron command section. The given cron command must be a 'normalized' list with only comma separated integers or '*'

Parameters
string$commandExpression,:cron command
int$numberToMatch,:number to look up
Returns
bool TRUE if number is in list

Definition at line 188 of file CronCommand.php.

Referenced by CronCommand\dayMatchesCronCommand(), and CronCommand\minuteAndHourMatchesCronCommand().

minuteAndHourMatchesCronCommand (   $timestamp)
protected

Determine if current timestamp matches minute and hour cron command restriction.

Parameters
int$timestampto test
Returns
bool TRUE if cron command conditions are met

Definition at line 138 of file CronCommand.php.

References CronCommand\$timestamp, and CronCommand\isInCommandList().

Referenced by CronCommand\calculateNextValue().

numberOfSecondsInDay (   $timestamp)
protected

Helper method to calculate number of seconds in a day.

This is not always 86400 (60*60*24) and depends on the timezone: Some countries like Germany have a summertime / wintertime switch, on every last sunday in march clocks are forwarded by one hour (set from 2:00 to 3:00), and on last sunday of october they are set back one hour (from 3:00 to 2:00). This shortens and lengthens the length of a day by one hour.

Parameters
int$timestampUnix timestamp
Returns
int Number of seconds of day

Definition at line 211 of file CronCommand.php.

References CronCommand\$timestamp.

Referenced by CronCommand\calculateNextValue().

roundTimestamp (   $timestamp)
protected

Round a timestamp down to full minute.

Parameters
int$timestampUnix timestamp
Returns
int Rounded timestamp

Definition at line 226 of file CronCommand.php.

References CronCommand\$timestamp.

Referenced by CronCommand\__construct().

Member Data Documentation

array $cronCommandSections
protected

Normalized sections of the cron command. Allowed are comma separated lists of integers and the character '*'

field lower and upper bound


minute 0-59 hour 0-23 day of month 1-31 month 1-12 day of week 1-7

Definition at line 36 of file CronCommand.php.

Referenced by CronCommand\getCronCommandSections().

$timestamp
protected

Timestamp of next execution date. This value starts with 'now + 1 minute' if not set externally by unit tests. After a call to calculateNextValue() it holds the timestamp of the next execution date which matches the cron command restrictions.

Definition at line 44 of file CronCommand.php.

Referenced by CronCommand\__construct(), CronCommand\dayMatchesCronCommand(), CronCommand\getTimestamp(), CronCommand\minuteAndHourMatchesCronCommand(), CronCommand\numberOfSecondsInDay(), and CronCommand\roundTimestamp().