TimeInterval
The TimeInterval helper to format a duration.
Tags
Table of Contents
Properties
- $days : int|float|null
- $hours : int|float|null
- $hoursPerDay : int|null
- $minutes : int|float|null
- $seconds : int|float|null
- $daysRegex : string
- $hoursRegex : string
- $minutesRegex : string
- $output : string|int
- $secondsRegex : string
Methods
- __construct() : mixed
- Creates a new TimeInterval instance.
- formatted() : string
- Returns the duration as a colon formatted string
- humanize() : string
- Returns the duration as a human-readable string.
- parse() : self|bool
- Attempt to parse one of the forms of duration.
- toMinutes() : int|float
- Returns the duration as an amount of minutes.
- toSeconds() : int|float
- Returns the duration as an amount of seconds.
- numberBreakdown() : array<string|int, mixed>
- output() : string
- Returns the output of the Duration object and resets.
- reset() : void
- Resets the Duration object by clearing the output and values.
Properties
$days
public
int|float|null
$days
$hours
public
int|float|null
$hours
$hoursPerDay
public
int|null
$hoursPerDay
$minutes
public
int|float|null
$minutes
$seconds
public
int|float|null
$seconds
$daysRegex
private
string
$daysRegex
$hoursRegex
private
string
$hoursRegex
$minutesRegex
private
string
$minutesRegex
$output
private
string|int
$output
$secondsRegex
private
string
$secondsRegex
Methods
__construct()
Creates a new TimeInterval instance.
public
__construct([int|float|string|null $duration = null ][, int $hoursPerDay = 24 ]) : mixed
Parameters
- $duration : int|float|string|null = null
- $hoursPerDay : int = 24
formatted()
Returns the duration as a colon formatted string
public
formatted([int|float|string|null $duration = null ][, bool $zeroFill = false ]) : string
For example, one hour and 42 minutes would be "1:43" With $zeroFill to true :
- 42 minutes would be "0:42:00"
- 28 seconds would be "0:00:28"
Parameters
- $duration : int|float|string|null = null
-
A string or number, representing a duration
- $zeroFill : bool = false
-
A boolean, to force zero-fill result or not (see example)
Return values
stringhumanize()
Returns the duration as a human-readable string.
public
humanize([int|float|string|null $duration = null ]) : string
For example, one hour and 42 minutes would be "1h 42m"
Parameters
- $duration : int|float|string|null = null
-
A string or number, representing a duration
Return values
stringparse()
Attempt to parse one of the forms of duration.
public
parse(int|float|string|null $duration) : self|bool
Parameters
- $duration : int|float|string|null
-
A string or number, representing a duration
Return values
self|bool —returns the Duration object if successful, otherwise false
toMinutes()
Returns the duration as an amount of minutes.
public
toMinutes([int|float|string|null $duration = null ][, int|bool $precision = false ]) : int|float
For example, one hour and 42 minutes would be "102" minutes
Parameters
- $duration : int|float|string|null = null
-
A string or number, representing a duration
- $precision : int|bool = false
-
Number of decimal digits to round to. If set to false, the number is not rounded.
Return values
int|floattoSeconds()
Returns the duration as an amount of seconds.
public
toSeconds([int|float|string|null $duration = null ][, int|bool $precision = false ]) : int|float
For example, one hour and 42 minutes would be "6120"
Parameters
- $duration : int|float|string|null = null
-
A string or number, representing a duration
- $precision : int|bool = false
-
Number of decimal digits to round to. If set to false, the number is not rounded.
Return values
int|floatnumberBreakdown()
private
numberBreakdown(float $number) : array<string|int, mixed>
Parameters
- $number : float
Return values
array<string|int, mixed>output()
Returns the output of the Duration object and resets.
private
output() : string
Tags
Return values
stringreset()
Resets the Duration object by clearing the output and values.
private
reset() : void