Oihana PHP

DurationUnit

Defines the canonical single-letter suffixes of a duration unit.

Using these constants instead of the raw 'd' / 'h' / 'm' / 's' magic strings keeps the parser and the formatter in sync — for instance the unit strings consumed by durationToSeconds() and produced by humanizeDuration().

Tags
example
use oihana\core\date\DurationUnit;
use function oihana\core\date\durationToSeconds;

echo durationToSeconds( '1' . DurationUnit::HOUR . ' 30' . DurationUnit::MINUTE ) ; // 5400
author

Marc Alcaraz (ekameleon)

since
1.2.0

Table of Contents

Constants

DAY  : string = 'd'
The day suffix.
HOUR  : string = 'h'
The hour suffix.
MINUTE  : string = 'm'
The minute suffix.
SECOND  : string = 's'
The second suffix.

Methods

all()  : array<string|int, string>
Returns the list of valid duration unit suffixes, from the largest to the smallest.
isValid()  : bool
Checks if a given value is a valid duration unit suffix.

Constants

DAY

The day suffix.

public string DAY = 'd'

Type: string

HOUR

The hour suffix.

public string HOUR = 'h'

Type: string

MINUTE

The minute suffix.

public string MINUTE = 'm'

Type: string

SECOND

The second suffix.

public string SECOND = 's'

Type: string

Methods

all()

Returns the list of valid duration unit suffixes, from the largest to the smallest.

public static all() : array<string|int, string>
Return values
array<string|int, string>

isValid()

Checks if a given value is a valid duration unit suffix.

public static isValid(string $value) : bool
Parameters
$value : string
Return values
bool
On this page

Search results