durationToSeconds.php
Table of Contents
Functions
- durationToSeconds() : float
- Normalizes a duration expressed in any supported form into a number of seconds.
Functions
durationToSeconds()
Normalizes a duration expressed in any supported form into a number of seconds.
durationToSeconds([int|float|string|null $duration = null ][, int $hoursPerDay = 24 ]) : float
The $duration may be:
- an int|float number of seconds (e.g.
3725), returned as-is (cast to float), - a colon string
"MM:SS"or"HH:MM:SS", - a unit string
"1.5d 3h 15m 12.5s"(any subset, any order, decimals allowed), - or
null(treated as a zero duration →0.0).
A day is worth $hoursPerDay hours, so the d unit of a unit string is
converted accordingly (a colon string never carries a day component).
Parameters
- $duration : int|float|string|null = null
-
The duration to convert.
- $hoursPerDay : int = 24
-
Hours in a day for the
dunit (default 24).
Tags
Return values
float —The total number of seconds (0.0 for an empty duration).