Timestamps
When a message was sent, worded by how long ago, beside it or across the thread.
Installation
npx shadcn@latest add "@aiellie/timestamps"shadcn needs the @aiellie registry in components.json first. npx aiellie add timestamps adds it on its first run, then installs the same way.
Timestamps says when a message was sent, worded by how long ago. Within the hour it says the gap, like "4 minutes ago". Earlier the same day it says the time, and before that the day. format picks one of those wordings for good.
TimestampRow puts it beside a message, and can keep it hidden until the row is hovered or focused, holding its space so the message never moves.
Getting started
Put it beside a message
livekeeps a relative label current, ticking every minute.components/stamped-message.tsximport { Message, MessageContent, MessagePart, } from "@/components/aiellie/message" import { Timestamp, TimestampRow } from "@/components/aiellie/timestamps" export function StampedMessage({ text, sentAt }: { text: string; sentAt: Date }) { return ( <TimestampRow align="end" reveal="hover"> <Message align="end"> <MessageContent> <MessagePart>{text}</MessagePart> </MessageContent> </Message> <Timestamp date={sentAt} live /> </TimestampRow> ) }Or across the thread
components/thread.tsx<Timestamp date={sentAt} format="datetime" variant="separator" />
Anatomy
<div data-slot="timestamp-row" data-align="end" data-reveal="hover">
{/* the message */}
<time data-slot="timestamp" dateTime="…" title="…"> {/* marker */}
<span data-slot="marker-content" />
</time>
</div>It's a time element with the full date as its title. The wording is worked out in the browser only, since the server doesn't know the reader's clock or time zone.
Every live timestamp ticking at the same rate shares one timer.
Examples
Formats
The same moment, three hours ago, in each format.
API reference
Timestamp
| Prop | Type | Default | Description |
|---|---|---|---|
date | Date | string | number | required | |
format | "auto" | "relative" | "time" | "day" | "datetime" | "auto" | |
variant | "default" | "separator" | "border" | "default" | The marker's look. |
live | boolean | number | false | Keeps it current: every minute, or every so many milliseconds. |
locale, hour12 | the reader's | ||
icon | ReactNode | Before the label. | |
children | ReactNode | Your own label. |
All other marker props are forwarded. formatTimestamp(date, options) gives the label as a string.
TimestampRow
| Prop | Type | Default | Description |
|---|---|---|---|
align | "start" | "end" | "start" | Which side the message sits on. |
reveal | "always" | "hover" | "always" | Shows the timestamp only on hover or focus. |