Documentation

TimeInterval extends DateInterval
in package
implements Stringable

Extends \DateInterval with some extra features for SMF.

Table of Contents

Interfaces

Stringable

Methods

__construct()  : mixed
Constructor.
__toString()  : string
Formats the object as a string so it can be reconstructed later.
createFromDateInterval()  : TimeInterval
Convert a \DateInterval object into a TimeInterval object.
localize()  : string
Formats the interval as a human-readable string in the current user's language.
toParsable()  : string
Formats the object as a string that can be parsed by strtotime().
toSeconds()  : int|float
Converts this interval to a number of seconds.

Methods

__construct()

Constructor.

public __construct(string $duration) : mixed

Like \DateInterval::__construct(), except that it can accept fractional values for whatever the smallest unit is. In other words, it supports the complete spec for ISO 8601 durations, not just a subset of the spec.

Parameters
$duration : string

An ISO 8601 duration string.

__toString()

Formats the object as a string so it can be reconstructed later.

public __toString() : string
Return values
string

A ISO 8601 duration string suitable for reconstructing this object.

createFromDateInterval()

Convert a \DateInterval object into a TimeInterval object.

public static createFromDateInterval(string $object) : TimeInterval
Parameters
$object : string

A \DateInterval object.

Return values
TimeInterval

A TimeInterval object.

localize()

Formats the interval as a human-readable string in the current user's language.

public localize([array<string|int, mixed> $format_chars = ['y', 'm', 'd'] ]) : string
Parameters
$format_chars : array<string|int, mixed> = ['y', 'm', 'd']

Properties to include in the output. Allowed values in this array: 'y', 'm', 'd', 'h', 'i', 's', 'f', 'a'. Note that when 'f' is included, it will always be combined with 's' in order to produce a single float value in the output.

Return values
string

A human-readable string.

toParsable()

Formats the object as a string that can be parsed by strtotime().

public toParsable() : string
Return values
string

A strtotime parsable string suitable for reconstructing this object.

toSeconds()

Converts this interval to a number of seconds.

public toSeconds(DateTimeInterface $when) : int|float

Because months have variable lengths, leap years exist, etc., it is necessary to provide a reference date that the interval will measure from in order to calculate the exact number of seconds.

Parameters
$when : DateTimeInterface

Reference date that this interval will be added to in order to calculate the exact number of seconds.

Return values
int|float

Number of seconds in this interval, counting from the reference date.


        
On this page

Search results