Usage
Timestamp displays an ISO 8601 instant with native <time> semantics. It can use localized absolute text, stable system text, or relative language such as “2 hours ago”.
Importing the component registers its custom element:
import "@nordhealth/components/lib/Timestamp"
Set the HTML value attribute to an ISO 8601 string. When assigning through JavaScript, a finite numeric .value is interpreted as Unix seconds. Use auto when recent values should be relative and older values should settle into an absolute date and time:
Composition
Timestamp renders a native <time> element in Light DOM. The value identifies the instant, while format, time-zone, lang, live, and tooltip properties determine how that instant is presented without changing its machine-readable value.
Accepted ISO calendar profile
Timestamp accepts calendar dates with a four-digit year or a signed six-digit expanded year: YYYY-MM-DD or ±YYYYYY-MM-DD. Append THH:mm, optional :ss, optional 1–9 digit fractional seconds, and optional Z or ±HH:mm offset for a date-time. T and Z are case-insensitive. Months are 01–12, days must exist in the Gregorian calendar, hours are 00–23, minutes and seconds are 00–59, and offsets are 00:00–23:59. 24:00 is valid only when minutes, seconds, and fractions are zero; -000000, week dates, ordinal dates, basic forms, prose dates, space separators, leap seconds, and other invalid fields are rejected.
Date-only values mean midnight UTC. A date-time without Z or an offset uses the runtime’s local timezone. Explicit offsets determine the instant, while time-zone affects formatting only. JavaScript Date stores milliseconds, so accepted fractional digits after the first three are truncated.
Examples
Formats
Timestamp supports relative, auto, date, date-time, time, system-date, system-date-time, and system-time. Localized formats follow the effective host or document language; system formats use stable, zero-padded astronomical years. Localized BCE values include an era so year zero and earlier dates remain unambiguous.
Relative boundaries
Relative output works for past and future values without rounding across the next unit. Units change at 60 seconds, 60 minutes, 24 hours, 30 days, and 365 days. Future values within 30 seconds are treated as clock skew and displayed as the present.
Relative examples sample one current time when each story renders, so they remain meaningful in normal Storybook use. The visual-regression runner freezes that render-time clock to keep screenshots deterministic.
Automatic threshold
auto-threshold is the maximum distance in seconds for relative output. Its default is 604800 seconds (one week). Outside the threshold, auto uses date-time.
Timezones
Use time-zone with an IANA timezone such as Europe/Helsinki. Add show-time-zone to localized formats when the short timezone name is useful context.
Localization
Localized formats, relative phrases, and accessible full detail follow the host lang, or the document lang when the component has no override. Native Intl localization works even when Nord component translations are not registered for that language, and changing lang after connection updates the output.
Live relative time
Add live to update at the next meaningful relative-time boundary. Timestamp pauses while the document is hidden and stops timers when disconnected or when automatic output becomes absolute.
Full detail tooltip
Relative output always exposes the full localized absolute value as its accessible name. show-tooltip makes that same detail available visually on hover or keyboard focus without using the HTML title attribute.
Invalid values
Missing, malformed, non-finite, or out-of-range values render no <time> content and do not create a live timer.
Accessibility
- Timestamp renders a native
<time datetime="…">element in light DOM so its machine-readable instant remains available to browsers and assistive technology. - Relative output has a localized full date and time as its accessible name. Tooltip-enabled relative values become keyboard focusable; absolute and tooltip-free values do not add a tab stop.
- Avoid relying on relative text alone when an exact instant is important. Enable the tooltip or choose an absolute format.
API reference
Timestamp
Timestamp presents an instant as localized, stable system, relative, or automatically selected text while retaining native date-time semantics.
<nord-timestamp></nord-timestamp>Props
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
value | value | The instant to display. Strings use Timestamp's documented ISO calendar profile; finite numbers assigned through JavaScript are Unix seconds. | string | number | undefined | — |
format | format | The display format. Automatic format uses relative text near the instant. | TimestampFormat | 'auto' |
autoThreshold | auto-threshold | Maximum age, in seconds, for relative output in automatic format. | unknown | DEFAULT_AUTO_THRESHOLD |
showTooltip | show-tooltip | Shows the full absolute timestamp in a Nord Tooltip for relative output. | boolean | false |
showTimeZone | show-time-zone | Adds a short timezone name to localized formats which include time. | boolean | false |
timeZone | time-zone | IANA timezone used for formatting. Defaults to the runtime timezone. | string | undefined | — |
live | live | Updates relative and automatic output at meaningful display boundaries. | boolean | false |
size | size | Optional Nord text size. Omit it to inherit the surrounding font size. | TimestampSize | undefined | — |
color | color | Optional Nord text color. | TimestampColor | undefined | — |
weight | weight | Optional Nord text weight. Omit it to inherit the surrounding weight. | TimestampWeight | undefined | — |
CSS Properties
CSS Custom Properties provide more fine grain control over component presentation. We advise utilizing existing properties on the component before using these.
| Property | Description | Default |
|---|---|---|
--n-timestamp-color | Controls the timestamp text color. | var(--n-color-text-weaker) |
--n-timestamp-font-size | Controls the timestamp font size. By default it inherits from surrounding text. | — |
--n-timestamp-font-weight | Controls the timestamp font weight. By default it inherits from surrounding text. | — |
Dependencies
This component is internally dependent on the following components:
Design guidelinesFor designers
Usage
This section includes guidelines for designers and developers about the usage of this component in different contexts.
Do
- Use Timestamp for dates and times that need consistent native semantics and localized presentation.
- Use
relativefor recent activity, orautowhen older values should become a stable date and time. - Set
langon the component, or on the document as a fallback, to localize Intl output even when that language has no registered Nord component translation. - Enable
show-tooltipwhen people benefit from inspecting the full absolute date and time behind relative text. - Use
liveonly when the relative phrase needs to remain current while it is visible.
Don’t
- Don’t provide prose or locale-specific date strings; use an ISO 8601 value or assign finite Unix seconds through JavaScript.
- Don’t enable live updates for absolute formats, where the displayed value does not change.
- Don’t use Timestamp for editable date or time input.
Accepted values
String values use a strict ISO calendar profile: a four-digit year or signed six-digit expanded year, followed by -MM-DD. The date may be followed by THH:mm, optional :ss, optional 1–9 digit fractional seconds, and optional Z or ±HH:mm offset. The T and Z literals are case-insensitive. Months are 01–12, days must exist in the Gregorian calendar, hours are 00–23, minutes and seconds are 00–59, and offsets are 00:00–23:59. 24:00 is accepted only when every smaller field is zero, and the ISO-invalid expanded year -000000 is rejected. Week dates, ordinal dates, basic/unseparated forms, prose dates, space separators, and leap seconds are not accepted.
Date-only strings represent midnight UTC. Date-times without Z or an offset represent local time in the runtime timezone. A supplied offset determines the instant; the component’s time-zone option changes presentation only, never parsing. Fractions beyond milliseconds are accepted and truncated by JavaScript Date precision.