Format
API reference › Debug Core › Helper › Format
Formats values, timestamps, and type labels for display in debug-panel views and toolbar chips.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
bytesToMb() static | Returns a N.NN MB string for the given byte count, rounded to the requested precision. | Format |
cssPercent() static | Returns a CSS percentage (42%, 33.333%) with at most three decimals and trailing zeros trimmed. | Format |
milliseconds() static | Returns a N ms readout for the given duration in seconds, grouped in thousands. | Format |
relativeTime() static | Returns a coarse age label for the given elapsed seconds: just now under a minute, then X min ago, X h ago, and X d ago. Ages of 30 days or more fall back to $fallback. | Format |
timeOfDay() static | Returns the wall-clock readout of the given epoch milliseconds, suffixed with the millisecond fraction (H:i:s.mmm). | Format |
typeOf() static | Returns the display label of a value’s type, with the element count for arrays and the byte length for strings. | Format |
Constants
Section titled “Constants”| Constant | Value | Description | Defined by |
|---|---|---|---|
BYTES_PER_MB | 1024 * 1024 | Bytes in one mebibyte, the unit of the bytesToMb() readout. | Format |
MILLISECONDS_PER_SECOND | 1000 | Milliseconds in one second, used to scale second-based durations. | Format |
Method details
Section titled “Method details”bytesToMb()
Section titled “bytesToMb() ”public static function bytesToMb(float|int $bytes, int $precision = 2): stringReturns a N.NN MB string for the given byte count, rounded to the requested precision.
Parameters
| Parameter | Type | Description |
|---|---|---|
$bytes | float| | Byte count to format. |
$precision | int | Number of decimal places. |
Returns
string: Megabyte readout.
cssPercent()
Section titled “cssPercent() ”public static function cssPercent(float $value): stringReturns a CSS percentage (42%, 33.333%) with at most three decimals and trailing zeros trimmed.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float | Percentage value to format. |
Returns
string: CSS percentage.
milliseconds()
Section titled “milliseconds() ”public static function milliseconds(float $seconds, int $decimals = 0): stringReturns a N ms readout for the given duration in seconds, grouped in thousands.
Parameters
| Parameter | Type | Description |
|---|---|---|
$seconds | float | Duration in seconds. |
$decimals | int | Number of decimal places. |
Returns
string: Millisecond readout.
relativeTime()
Section titled “relativeTime() ”public static function relativeTime(int $elapsedSeconds, string $fallback): stringReturns a coarse age label for the given elapsed seconds: just now under a minute, then X min ago, X h ago,
and X d ago. Ages of 30 days or more fall back to $fallback.
The caller supplies the elapsed seconds so the clock source stays at the call site.
Parameters
| Parameter | Type | Description |
|---|---|---|
$elapsedSeconds | int | Age in seconds, typically time() - $capturedAt. |
$fallback | string | Absolute label used past the 30-day threshold. |
Returns
string: Age label, or $fallback when the age reaches 30 days.
timeOfDay()
Section titled “timeOfDay() ”public static function timeOfDay(int $epochMilliseconds, string $format = 'H:i:s'): stringReturns the wall-clock readout of the given epoch milliseconds, suffixed with the millisecond fraction
(H:i:s.mmm).
Negative timestamps use floor division, so the fraction stays in the 000-999 range and the seconds part
names the wall-clock second that contains the instant.
Parameters
| Parameter | Type | Description |
|---|---|---|
$epochMilliseconds | int | Unix timestamp in milliseconds. |
$format | string | date() format for the second-precision part, without the fraction separator. |
Returns
string: Formatted timestamp followed by .mmm.
typeOf()
Section titled “typeOf() ”public static function typeOf(mixed $value): stringReturns the display label of a value’s type, with the element count for arrays and the byte length for strings.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | mixed | JSON-safe value to describe. |
Returns
string: Type label such as array(3), string(16), int, float, bool, or null.