Skip to main content
The time utility module provides framework-agnostic date/time formatting, ISO 8601 duration parsing, and a React component for auto-updating relative time displays. All instances share a single setInterval — no per-component timers.

Installation

The time utilities are part of @apollo-deploy/components:

Format modes

Six display formats are supported via formatRelative() (or the RelativeTime component’s format prop):

RelativeTime — Auto-updating component

The RelativeTime component renders a relative time string that automatically updates every second using a shared module-level clock.

Props

Datetime-specific props (forwarded to Intl.DateTimeFormat):

formatRelative() — Framework-agnostic formatter

Use formatRelative() when you need formatted output without a React component (e.g. in server components, API responses, or plain functions).

Options

The RelativeTimeOptions object accepts the same options as the RelativeTime component plus:

Convenience formatters

Shorthand functions for specific formats:

Duration — ISO 8601 duration parser

Parse and manipulate ISO 8601 duration strings like "P1DT2H30M" or "PT5M30S".

Note on approximations

Months and years use approximate conversions (30 days/month, 365 days/year). For exact calendar math, use date-fns or a dedicated date library.

timezone() — Detect user timezone

Returns the browser’s IANA timezone string using Intl.DateTimeFormat.
Returns undefined if Intl is not available.

Ago (deprecated)

The Ago component and agoString function are deprecated. Use RelativeTime instead.

Type reference