CronCommand
This class provides calculations for the cron command format.
Table of Contents
Properties
- $cronCommandSections : array<string|int, mixed>
- Normalized sections of the cron command.
- $timestamp : int
- Timestamp of next execution date.
Methods
- __construct() : mixed
- Constructor
- calculateNextValue() : mixed
- Calculates the date of the next execution.
- getCronCommandSections() : array<string|int, mixed>
- Get cron command sections. Array of strings, each containing either a list of comma separated integers or *
- getTimestamp() : int
- Get next timestamp
- dayMatchesCronCommand() : bool
- Determine if current timestamp matches day of month, month and day of week cron command restriction
- isInCommandList() : bool
- 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 '*'
- minuteAndHourMatchesCronCommand() : bool
- Determine if current timestamp matches minute and hour cron command restriction.
- numberOfSecondsInDay() : int
- Helper method to calculate number of seconds in a day.
- roundTimestamp() : int
- Round a timestamp down to full minute.
Properties
$cronCommandSections
Normalized sections of the cron command.
protected
array<string|int, mixed>
$cronCommandSections
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
$timestamp
Timestamp of next execution date.
protected
int
$timestamp
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.
Methods
__construct()
Constructor
public
__construct(string $cronCommand[, bool|int $timestamp = false ]) : mixed
Parameters
- $cronCommand : string
-
The cron command can hold any combination documented as valid
- $timestamp : bool|int = false
-
Optional start time, used in unit tests
calculateNextValue()
Calculates the date of the next execution.
public
calculateNextValue() : mixed
Tags
getCronCommandSections()
Get cron command sections. Array of strings, each containing either a list of comma separated integers or *
public
getCronCommandSections() : array<string|int, mixed>
Return values
array<string|int, mixed> —command sections:
getTimestamp()
Get next timestamp
public
getTimestamp() : int
Return values
int —Unix timestamp
dayMatchesCronCommand()
Determine if current timestamp matches day of month, month and day of week cron command restriction
protected
dayMatchesCronCommand(int $timestamp) : bool
Parameters
- $timestamp : int
-
to test
Return values
bool —TRUE if cron command conditions are met
isInCommandList()
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 '*'
protected
isInCommandList(string $commandExpression, int $numberToMatch) : bool
Parameters
- $commandExpression : string
-
cron command
- $numberToMatch : int
-
number to look up
Return values
bool —TRUE if number is in list
minuteAndHourMatchesCronCommand()
Determine if current timestamp matches minute and hour cron command restriction.
protected
minuteAndHourMatchesCronCommand(int $timestamp) : bool
Parameters
- $timestamp : int
-
to test
Return values
bool —TRUE if cron command conditions are met
numberOfSecondsInDay()
Helper method to calculate number of seconds in a day.
protected
numberOfSecondsInDay(int $timestamp) : int
This is not always 86400 (606024) 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
- $timestamp : int
-
Unix timestamp
Return values
int —Number of seconds of day
roundTimestamp()
Round a timestamp down to full minute.
protected
roundTimestamp(int $timestamp) : int
Parameters
- $timestamp : int
-
Unix timestamp
Return values
int —Rounded timestamp