Time Ago Card
The TimeAgoCard component displays a timestamp in a human-readable format, such as “5 min. ago”. Hovering (or focusing) the value reveals a tooltip with the full date and time in both UTC and the local timezone.
Variations
Timestamp variants
The timestamp prop accepts an ISO 8601 string, a Unix timestamp number, or null. When omitted, nothing is rendered.
Time difference examples
The component displays relative time in a narrow format for all time ranges:
Future timestamps
The component also handles future timestamps:
With prefix
Live updating
Set live to have the relative time re-render every second so it stays current without a page refresh.
Installation
import { TimeAgoCard } from "@harnessio/ui/components";
<TimeAgoCard timestamp={new Date().toISOString()} />;Anatomy
TimeAgoCard renders a trigger showing the relative time, with a tooltip that reveals the full date.
- The trigger is a
<button>wrapping aTextrendered as a<time>element (with adateTimeattribute). It shows the relative time (prefixed withprefixwhen provided). - On hover or focus, a tooltip opens showing the full date and time in two rows — UTC and the local timezone — each with a
StatusBadgelabel. - Relative time is formatted with the native
Intl.RelativeTimeFormatin thenarrowstyle, so output is abbreviated (e.g. “5 min. ago”, “2 days ago”, “in 1 yr.”) and localized to the user’s locale.
Best practices
Do
- Use
prefixto give the timestamp context (“Updated”, “Created”) when the surrounding text doesn’t already. - Use
livefor timestamps a user watches in real time (e.g. a recently-triggered run), and leave it off for static lists to avoid unnecessary re-renders. - Pass a valid ISO 8601 string or Unix timestamp so the value always renders.
Don’t
- Don’t rely on
TimeAgoCardalone to convey a critical exact time — the precise value lives in the hover tooltip, which isn’t visible at a glance. - Don’t pass a
Dateobject; the prop expects a string, number, ornull.
Accessibility
Keyboard
- The trigger is a real
<button>, so it is focusable and the full-date tooltip opens on focus as well as hover.
Labeling & semantics
- The relative time is rendered inside a
<time>element with adateTimeattribute, giving assistive tech and machines a precise, parseable value behind the human-readable text.
Properties
Prop | Required | Default | Type |
|---|---|---|---|
| timestamp | false | string | number | null | |
| prefix | false | string | |
| live | false | false | boolean |
| textProps | false | Omit<TextProps<'time' | 'span'>, 'ref'> | |
| tooltipProps | false | TooltipProps | |
| triggerProps | false | Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'className'> | |
| triggerClassName | false | string |