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.
timestamp is the time to display (an ISO string or Unix number), rendered as a relative “time ago” value — past and future times are both supported. Add a prefix such as “Updated” for context, and set live to have the value re-render every second so it stays current. Try them in the playground below.
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.
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.
Content
- The relative time is generated and localized for you — the only text you write is the
prefix. - Keep the
prefixto a short label, usually a past-tense verb like “Updated”, “Created”, or “Last run”. - Don’t append “on”, “at”, or “ago” to the
prefix— the component already reads as “Updated 5 min. ago”, so extra connecting words make it redundant. - Match the casing of the surrounding UI; use sentence case (“Last updated”) unless the context calls for a capitalized label.
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 |