CRM_Utils_Time
in package
Date time utilties
Table of Contents
Properties
- $callback : callable|null
- A function which determines the current time.
Methods
- date() : string
- Format a date/time expression.
- delta() : int
- Get the simulation offset.
- getTime() : string
- Get the time.
- getTimeRaw() : int
- Get the time.
- getTimeZoneOffsetFromString() : string|false|null
- Get timezone offset from a timezone string
- isEqual() : bool
- Approximate time-comparison. $a and $b are considered equal if they are within $threshold seconds of each other.
- resetTime() : mixed
- Remove any time overrides.
- setTime() : string
- Set the given time.
- strtotime() : false|int
- Evaluate a time expression (relative to current time).
- time() : int
- Get the time.
Properties
$callback
A function which determines the current time.
private
static callable|null
$callback
= \NULL
Only used during testing (with mocked time).
The normal value, NULL, indicates the use of real time.
Methods
date()
Format a date/time expression.
public
static date(string $format[, null|int $timestamp = NULL ]) : string
Parameters
- $format : string
-
Ex: 'Y-m-d H:i:s'
- $timestamp : null|int = NULL
-
The time (seconds since epoch). NULL will use current time.
Tags
Return values
string —Ex: '2001-02-03 04:05:06'
delta()
Get the simulation offset.
public
static delta() : int
Return values
int —Seconds between logical time and real time.
getTime()
Get the time.
public
static getTime([string $returnFormat = 'YmdHis' ]) : string
Prefer CRM_Utils_Time::date(), whose name looks similar to the stdlib work-a-like.
Parameters
- $returnFormat : string = 'YmdHis'
-
Format in which date is to be retrieved.
Return values
stringgetTimeRaw()
Get the time.
public
static getTimeRaw() : int
Prefer CRM_Utils_Time::time(), whose name looks similar to the stdlib work-a-like.
Return values
int —seconds since epoch
getTimeZoneOffsetFromString()
Get timezone offset from a timezone string
public
static getTimeZoneOffsetFromString(string $timezone) : string|false|null
Parameters
- $timezone : string
Return values
string|false|nullisEqual()
Approximate time-comparison. $a and $b are considered equal if they are within $threshold seconds of each other.
public
static isEqual(string $a, string $b[, int $threshold = 0 ]) : bool
Parameters
- $a : string
-
Time which can be parsed by strtotime.
- $b : string
-
Time which can be parsed by strtotime.
- $threshold : int = 0
-
Maximum allowed difference (in seconds).
Return values
boolresetTime()
Remove any time overrides.
public
static resetTime() : mixed
setTime()
Set the given time.
public
static setTime(string $newDateTime[, string $returnFormat = 'YmdHis' ]) : string
Parameters
- $newDateTime : string
-
A date formatted with strtotime.
- $returnFormat : string = 'YmdHis'
-
Format in which date is to be retrieved.
Note: The progression of time will be influenced by TIME_FUNC, which may be:
- 'frozen' (time does not move)
- 'natural' (time moves naturally)
- 'linear:XXX' (time moves in increments of XXX milliseconds - with every lookup)
- 'prng:XXX' (time moves by random increments, between 0 and XXX milliseconds)
Return values
stringstrtotime()
Evaluate a time expression (relative to current time).
public
static strtotime(string $str[, string|int $now = 'time()' ]) : false|int
Parameters
- $str : string
-
Ex: '2001-02-03 04:05:06' or '+2 days'
- $now : string|int = 'time()'
-
For relative time strings, $now determines the base time.
Tags
Return values
false|int —The indicated time (seconds since epoch)
time()
Get the time.
public
static time() : int
Tags
Return values
int —seconds since epoch