# Format

> Formats values, timestamps, and type labels for display in debug-panel views and toolbar chips.

[API reference](/docs/api/index.md) › [Debug Core](/docs/extensions/debug-core/reference/index.md) › [Helper](/docs/extensions/debug-core/reference/helper/index.md) › Format

| final class | `PHPForge\Debug\Helper\Format` |
| --- | --- |
| Source | [`src/Helper/Format.php`](https://github.com/php-forge/debug-core/blob/main/src/Helper/Format.php#L24) |

Formats values, timestamps, and type labels for display in debug-panel views and toolbar chips.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`bytesToMb()`](#method-bytesToMb) static | Returns a `N.NN MB` string for the given byte count, rounded to the requested precision. | `Format` |
| [`cssPercent()`](#method-cssPercent) static | Returns a CSS percentage (`42%`, `33.333%`) with at most three decimals and trailing zeros trimmed. | `Format` |
| [`milliseconds()`](#method-milliseconds) static | Returns a `N ms` readout for the given duration in seconds, grouped in thousands. | `Format` |
| [`relativeTime()`](#method-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()`](#method-timeOfDay) static | Returns the wall-clock readout of the given epoch milliseconds, suffixed with the millisecond fraction (`H:i:s.mmm`). | `Format` |
| [`typeOf()`](#method-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

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-BYTES_PER_MB"></span>`BYTES_PER_MB` | `1024 * 1024` | Bytes in one mebibyte, the unit of the `bytesToMb()` readout. | `Format` |
| <span id="const-MILLISECONDS_PER_SECOND"></span>`MILLISECONDS_PER_SECOND` | `1000` | Milliseconds in one second, used to scale second-based durations. | `Format` |

## Method details

### bytesToMb() <span id="method-bytesToMb"></span>

```php
public static function bytesToMb(float|int $bytes, int $precision = 2): string
```

Returns a `N.NN MB` string for the given byte count, rounded to the requested precision.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$bytes` | `float\|int` | Byte count to format. |
| `$precision` | `int` | Number of decimal places. |

**Returns**

`string`: Megabyte readout.

### cssPercent() <span id="method-cssPercent"></span>

```php
public static function cssPercent(float $value): string
```

Returns 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() <span id="method-milliseconds"></span>

```php
public static function milliseconds(float $seconds, int $decimals = 0): string
```

Returns 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() <span id="method-relativeTime"></span>

```php
public static function relativeTime(int $elapsedSeconds, string $fallback): string
```

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`.

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() <span id="method-timeOfDay"></span>

```php
public static function timeOfDay(int $epochMilliseconds, string $format = 'H:i:s'): string
```

Returns 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() <span id="method-typeOf"></span>

```php
public static function typeOf(mixed $value): string
```

Returns 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`.