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 viaformatRelative() (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
TheRelativeTimeOptions 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, usedate-fns or a dedicated date library.
timezone() — Detect user timezone
Returns the browser’s IANA timezone string using Intl.DateTimeFormat.
undefined if Intl is not available.