humanizeDuration.php
Table of Contents
Functions
- humanizeDuration() : string
- Returns a human-readable representation of a duration, e.g. `"1d 2h 3m 4s"`.
Functions
humanizeDuration()
Returns a human-readable representation of a duration, e.g. `"1d 2h 3m 4s"`.
humanizeDuration([int|float|string|null $duration = null ][, int $hoursPerDay = 24 ]) : string
The $duration may be:
- an int|float number of seconds (e.g.
3725), - a colon string
"MM:SS"or"HH:MM:SS", - a unit string
"1.5d 3h 15m 12.5s"(any subset, any order), - or
null(treated as a zero duration →"0s").
Whatever the input form, the duration is first normalized into a number of
seconds and then broken down so that every component stays within its natural
range (seconds < 60, minutes < 60, hours < $hoursPerDay). Fractional input
therefore rolls up correctly: "90:00" and "1.5h" both yield "1h 30m".
Only the seconds component may carry a fractional part (e.g. "5.5s").
Parameters
- $duration : int|float|string|null = null
-
The duration to format.
- $hoursPerDay : int = 24
-
Hours in a day for day↔hour conversion (default 24).
Tags
Return values
string —The human-readable duration (e.g. "1h 42m"), "0s" for an empty duration.