Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

feat(core): add timezoneID prop to Timestamp (#9789)

Nenad Božidarević7efb4f7ad915
diff --git a/.changeset/timestamp-time-zone.md b/.changeset/timestamp-time-zone.md
new file mode 100644
index 0000000000..7b034fd820
--- /dev/null
+++ b/.changeset/timestamp-time-zone.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[feat] `Timestamp` takes a `timezoneID` prop naming the IANA zone its absolute formats render in, such as `'UTC'` or `'America/Los_Angeles'`. An explicit zone renders identically on the server and the client, so a server-rendered absolute time no longer depends on the server's zone and hydrates without a mismatch. Omit it (or pass `'local'`) to keep the viewer's own zone, relative formats' visible text ignores it (configured `tooltipEntries` rows still follow it), and an unknown identifier warns once in development and falls back to the viewer's zone.
+
+@nbozidarevic
diff --git a/apps/storybook/stories/Timestamp.stories.tsx b/apps/storybook/stories/Timestamp.stories.tsx
index 06dad8b2f9..c2e87f2634 100644
--- a/apps/storybook/stories/Timestamp.stories.tsx
+++ b/apps/storybook/stories/Timestamp.stories.tsx
@@ -241,6 +241,32 @@ export const DateTimeWithTimezone: Story = {
},
};
+export const ExplicitTimeZone: Story = {
+ name: 'Explicit time zone',
+ render: () => (
+ <div style={{display: 'flex', flexDirection: 'column', gap: '8px'}}>
+ <Timestamp
+ value="2026-02-19T17:00:00Z"
+ format="date_time"
+ timezoneID="UTC"
+ isTimezoneShown
+ />
+ <Timestamp
+ value="2026-02-19T17:00:00Z"
+ format="date_time"
+ timezoneID="America/Los_Angeles"
+ isTimezoneShown
+ />
+ <Timestamp
+ value="2026-02-19T17:00:00Z"
+ format="date_time"
+ timezoneID="Asia/Tokyo"
+ isTimezoneShown
+ />
+ </div>
+ ),
+};
+
export const TimeFormat: Story = {
args: {
value: '2026-02-19T17:00:00Z',
diff --git a/docs/specs/components/Timestamp/Timestamp.spec.md b/docs/specs/components/Timestamp/Timestamp.spec.md
index 736c8cc332..f4fede9f0d 100644
--- a/docs/specs/components/Timestamp/Timestamp.spec.md
+++ b/docs/specs/components/Timestamp/Timestamp.spec.md
@@ -82,9 +82,11 @@ Consumer migration instructions belong in consumer docs and release notes.
and no card opens, where `spec:AST-085` FR4 keeps focus on a control that
stays available.
- **Absolute formats depend on the server's zone (FR3).** An absolute format
- other than `unix_seconds` renders in the host's time zone, so the same instant reads "Mar 25" from a
+ other than `unix_seconds` renders in the host's time zone unless the caller
+ passes `timezoneID`, so without it the same instant reads "Mar 25" from a
UTC server and "Mar 26" from a Tokyo server, and a viewer in another zone
- gets a hydration text mismatch.
+ gets a hydration text mismatch. An explicit `timezoneID` pins the rendering
+ on the server and the client alike.
## Ownership boundary
@@ -121,11 +123,11 @@ Consumer migration instructions belong in consumer docs and release notes.
| ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
| FR1 | Timestamp renders a Text element (default `type="supporting"`, `color="secondary"`, with `size` and `weight` passed through) carrying the `timestamp` target, which reflects the resolved format beside Text's type and color reflection; inside it an inline `time` element inherits the typography and carries the instant's ISO 8601 `datetime`. An unparseable value renders nothing and logs a development warning. | Current source and tests |
| FR2 | `auto` shows `relative` when the instant is within `autoThreshold` seconds of now (default seven days) and `date_time` otherwise. `relative` uses the locale's long relative phrase and `relative_short` its narrow phrase; a value a few seconds in the future reads as "now". Absolute formats use the shared instant formatter in the provider locale. The date-bearing formats (`date`, `date_long`, `date_weekday`, `date_time`, and the full date of FR5 and FR7) write the date in the calendar that the provider resolves (`spec:AST-111` FR2, FR5, FR18), which is Gregorian unless the application selects another; a locale's default calendar never applies, and `date_time` keeps its time of day. Each names the month and day that `component:Calendar` shows. `time`, the relative formats, `system_*`, and `unix_seconds` do not depend on the calendar. `system_*` formats are machine-readable Gregorian ISO, and `unix_seconds` is zone-independent. `isTimezoneShown` appends the zone abbreviation to `date_time` and `time` only. | Current source and tests |
-| FR3 | Server markup does not depend on the server's time zone and hydrates without a mismatch. A format that needs the clock renders `date_time` in UTC and the Gregorian calendar with the zone shown until the client can read the clock; the client then shows the resolved format without committing the UTC placeholder. A calendar that needs `Temporal` hydrates without a mismatch only when the server and the browser resolve it the same way (the `spec:AST-013` FR12 exception). Implementation gap: absolute formats other than `unix_seconds` render in the host's time zone, so their server markup depends on the server's zone and hydrating it in another zone produces a text mismatch (Current-state impact). | Current source and tests |
+| FR3 | Server markup does not depend on the server's time zone and hydrates without a mismatch. A format that needs the clock renders `date_time` in UTC and the Gregorian calendar with the zone shown until the client can read the clock; the client then shows the resolved format without committing the UTC placeholder. A calendar that needs `Temporal` hydrates without a mismatch only when the server and the browser resolve it the same way (the `spec:AST-013` FR12 exception). Implementation gap: absolute formats other than `unix_seconds` render in the host's time zone unless the caller passes `timezoneID`, so without it their server markup depends on the server's zone and hydrating it in another zone produces a text mismatch (Current-state impact). | Current source and tests |
| FR4 | With `isLive` and relative output, the clock refreshes every second under a minute old, every 30 seconds under an hour, every minute under a day, and every five minutes beyond; the timer is cleared on unmount or when the inputs change. Locale changes update the output live. | Current source and tests |
| FR5 | Relative output is named by the full absolute date and the long time-zone name unless a caller names the element; absolute output adds no name. A caller's explicit `aria-label` reaches the element (`architecture:public-component-api` INV5). | Current source and tests |
| FR6 | When `hasTooltip` is true and the output is relative or `tooltipEntries` is non-empty, a lazily loaded HoverCard named "Timestamp details" attaches above the timestamp, opening on hover and on keyboard focus; the `time` element gains `tabIndex={0}`. Otherwise no card renders and no tab stop is added. Focus placed on the timestamp stays there when the card attaches (`spec:AST-085` FR4). Implementation gap: while the card module loads, a fallback `time` with the tab stop renders, and attaching the card replaces it, so focus placed on it falls to the page body and no card opens (Current-state impact). | Current source and tests |
-| FR7 | The card is a description list in a grid: an optional label column (present when any row has a label), the value column, and a trailing action column (present when any row is copyable). Without entries it has one copyable row with the full absolute time in the viewer's zone. Each configured entry is one row in the given order, rendered in its own time zone and format, read-only unless `isCopyable`. An unknown time zone does not crash. A description list holds only name-value groups (WCAG 2.2 1.3.1). Each row is a name-value group; a row without a label is named by its time zone's long name, which is visually hidden. A copy button sits inside its row's value. | Current source and tests |
+| FR7 | The card is a description list in a grid: an optional label column (present when any row has a label), the value column, and a trailing action column (present when any row is copyable). Without entries it has one copyable row with the full absolute time in the viewer's zone. Each configured entry is one row in the given order, rendered in its own time zone and format, read-only unless `isCopyable`. An entry without its own `timezoneID` renders in the Timestamp's `timezoneID` when one is set, else the viewer's zone. An unknown time zone does not crash. A description list holds only name-value groups (WCAG 2.2 1.3.1). Each row is a name-value group; a row without a label is named by its time zone's long name, which is visually hidden. A copy button sits inside its row's value. | Current source and tests |
| FR8 | A copy button is a small ghost IconButton on the `timestamp-copy-button` target, named "Copy {value}" with a "Copy" tooltip; activating it writes the row's value to the clipboard, switches to the copied glyph (`check` unless a theme maps `timestamp-copy`, FR10) and the "Copied" name and tooltip for 1.5 seconds, and announces "Copied" politely. A clipboard rejection does nothing. | Current source and tests |
| FR9 | `ref`, `data-testid`, and other supported DOM, ARIA, data, and event props reach the `time` element; `xstyle`, `className`, and `style` reach the Text wrapper. A caller `aria-labelledby` names the element in place of FR5's name. A caller's explicit `tabIndex` reaches the element (`architecture:public-component-api` INV5). | Current source and tests |
| FR10 | The copy button's glyph resolves through the `timestamp-copy` component icon slot, passing `{copied}`, which is true while the copied state (FR8) shows. With no theme entry, the glyph is `copy`, and `check` while copied. When the slot resolves to no icon (a theme value of `null`, a slot function that returns `null`, or a request with `icon: null`), only the glyph is hidden: the button keeps its size, name, tooltip, and copy behavior, and shows no glyph at rest or while copied. A request `size` changes only the glyph, never the button. | Proposal; `architecture:icon-resolution-and-component-slots/INV2,INV4–INV8` |
diff --git a/packages/core/api-report.md b/packages/core/api-report.md
index aec4d3e2d1..1fbf783309 100644
--- a/packages/core/api-report.md
+++ b/packages/core/api-report.md
@@ -2558,6 +2558,7 @@ component Timestamp(props: TimestampProps)
prop isTimezoneShown?: boolean = false
prop ref?: React.Ref<HTMLTimeElement>
prop size?: TextSize
+ prop timezoneID?: string
prop tooltipEntries?: ReadonlyArray<TimestampTooltipEntry> = undefined — a single default row with the full absolute time in the viewer's own time zone
prop type?: TextType = 'supporting'
prop value: string | number
diff --git a/packages/core/src/Timestamp/Timestamp.doc.mjs b/packages/core/src/Timestamp/Timestamp.doc.mjs
index c4784925da..6c3c184a37 100644
--- a/packages/core/src/Timestamp/Timestamp.doc.mjs
+++ b/packages/core/src/Timestamp/Timestamp.doc.mjs
@@ -6,7 +6,17 @@ export const docs = {
name: 'Timestamp',
displayName: 'Timestamp',
category: 'Content',
- keywords: ['date', 'time', 'datetime', 'relative', 'ago', 'clock', 'format', 'duration', 'relativetime'],
+ keywords: [
+ 'date',
+ 'time',
+ 'datetime',
+ 'relative',
+ 'ago',
+ 'clock',
+ 'format',
+ 'duration',
+ 'relativetime',
+ ],
playground: {
// `value` is required but has no semantic default, so the properties-tab
// preview fell back to the literal string "value" — which
@@ -31,6 +41,12 @@ export const docs = {
"Display format. 'relative' uses the locale's native long relative-time wording ('2 hours ago' in English), 'relative_short' uses its narrow pattern ('2h ago' in English) for compact surfaces, 'date' shows 'Mar 21, 2025', 'date_long' shows 'March 21, 2025', 'date_weekday' shows 'Wed, Mar 21, 2025', 'date_time' shows 'Mar 21, 2025, 2:51 PM', 'time' shows '2:51 PM', 'system_*' variants use ISO-style formatting, 'unix_seconds' shows the Unix time in whole seconds since the epoch (an absolute, zone-independent value), 'auto' switches from relative to date_time based on recency. Absolute formats never read the current time. 'relative', 'relative_short' and 'auto' read it on the client only: a server render or static prerender shows the full date and time in UTC, labelled, and the client switches to the format's normal output after hydration. Date-bearing formats ('date', 'date_long', 'date_weekday', 'date_time', and the full date in the hover card and the accessible name) use the InternationalizationProvider calendar, such as calendar=\"persian\"; 'time', the relative formats, 'system_*', and 'unix_seconds' do not change.",
default: "'auto'",
},
+ {
+ name: 'timezoneID',
+ type: 'string',
+ description:
+ "IANA time zone the absolute formats render in, such as 'UTC' or 'America/Los_Angeles'. Omit (or pass 'local') for the viewer's own zone. An explicit zone renders identically on the server and the client, so it is the way to show an absolute time without a hydration mismatch; relative formats' visible text ignores it, while configured tooltipEntries rows still follow it. An unknown identifier warns once in development and falls back to the viewer's zone.",
+ },
{
name: 'autoThreshold',
type: 'number',
@@ -49,13 +65,13 @@ export const docs = {
name: 'tooltipEntries',
type: 'ReadonlyArray<{timezoneID?: string; format?: TimestampTooltipFormat; label?: string; isCopyable?: boolean}>',
description:
- "Lines to show on hover, so one instant can be read (and optionally copied) in several time zones and/or formats at once. Each entry is one line, in the order given. Omit timezoneID (or pass 'local') for the viewer's own zone; format defaults to the full absolute style and also accepts 'full' alongside every non-relative TimestampFormat. Rows are read-only unless they set isCopyable (default false); copyable rows show a copy button in a dedicated trailing action column so buttons align, and the column is only present when some row is copyable. With no entries the card shows a single default row with the full absolute time, which is copyable. Configuring entries also attaches the surface to absolute formats, which otherwise have none.",
+ "Lines to show on hover, so one instant can be read (and optionally copied) in several time zones and/or formats at once. Each entry is one line, in the order given. An entry without timezoneID follows the Timestamp timezoneID when set, else the viewer's zone; 'local' always means the viewer's zone; format defaults to the full absolute style and also accepts 'full' alongside every non-relative TimestampFormat. Rows are read-only unless they set isCopyable (default false); copyable rows show a copy button in a dedicated trailing action column so buttons align, and the column is only present when some row is copyable. With no entries the card shows a single default row with the full absolute time, which is copyable. Configuring entries also attaches the surface to absolute formats, which otherwise have none.",
},
{
name: 'isTimezoneShown',
type: 'boolean',
description:
- 'Whether to append the timezone abbreviation to the visible text. Applies to the date_time and time formats; system_* formats stay machine-readable and never carry one. Use tooltipEntries to control the tooltip\'s time zones.',
+ "Whether to append the timezone abbreviation to the visible text. Applies to the date_time and time formats; system_* formats stay machine-readable and never carry one. Use tooltipEntries to control the tooltip's time zones.",
default: 'false',
},
{
@@ -68,7 +84,8 @@ export const docs = {
{
name: 'type',
type: "'body' | 'large' | 'label' | 'supporting' | 'code' | 'display-1' | 'display-2' | 'display-3' | 'inherit'",
- description: 'Semantic text type from Text. Determines size, weight, and line-height.',
+ description:
+ 'Semantic text type from Text. Determines size, weight, and line-height.',
default: "'supporting'",
},
{
@@ -115,24 +132,97 @@ export const docs = {
description:
'Timestamp formats a date or time value into human-readable text. Use it to show when something was created, updated, or is scheduled; picking relative for recency, absolute for precision, or auto to let the component decide.',
bestPractices: [
- {guidance: true, description: 'Use the auto format in feeds and lists so recent items show "2 hours ago" and older items show the full date automatically.'},
- {guidance: true, description: 'Keep formatting consistent within the same list or table; mixing relative and absolute timestamps in the same column confuses scanning.'},
- {guidance: true, description: 'Enable isTimezoneShown when the audience spans multiple time zones, like a global team calendar or audit log.'},
- {guidance: true, description: 'Use tooltipEntries when readers must compare zones, such as an incident log where the reader\'s time and the event\'s origin zone both matter.'},
- {guidance: true, description: 'Label every entry once a tooltip shows more than one zone; a bare abbreviation is not always recognizable (Tokyo renders as "GMT+9", not "JST").'},
- {guidance: true, description: 'Use isLive for active dashboards or real-time feeds so the relative time stays accurate without a page refresh.'},
- {guidance: true, description: 'Reach for tooltipEntries when readers need to grab an exact value: an incident log or deploy record where someone pastes the UTC time or Unix seconds elsewhere; configuring entries turns the hover into copy-to-clipboard rows.'},
- {guidance: false, description: 'Don\'t display raw Unix timestamps or ISO strings to users; always pass them through Timestamp to get a human-readable format.'},
- {guidance: false, description: 'Avoid system_date or system_time formats in user-facing UI; they are meant for developer tools, logs, and machine-readable contexts.'},
- {guidance: false, description: 'Don\'t disable the hover card on relative timestamps; users expect to hover for the full date when they see "3 hours ago".'},
- {guidance: false, description: 'Don\'t stack many zones into one card; it is capped at 300px wide and long labelled lines wrap. Two or three entries read well.'},
- {guidance: false, description: 'Don\'t pass a fixed-offset abbreviation like "EST" as timezoneID; it is a valid identifier but never observes daylight saving, so it reads an hour wrong for half the year. Use the region id, "America/New_York".'},
+ {
+ guidance: true,
+ description:
+ 'Use the auto format in feeds and lists so recent items show "2 hours ago" and older items show the full date automatically.',
+ },
+ {
+ guidance: true,
+ description:
+ 'Keep formatting consistent within the same list or table; mixing relative and absolute timestamps in the same column confuses scanning.',
+ },
+ {
+ guidance: true,
+ description:
+ 'Enable isTimezoneShown when the audience spans multiple time zones, like a global team calendar or audit log.',
+ },
+ {
+ guidance: true,
+ description:
+ "Use tooltipEntries when readers must compare zones, such as an incident log where the reader's time and the event's origin zone both matter.",
+ },
+ {
+ guidance: true,
+ description:
+ 'Pass timezoneID when an absolute time must read the same for every viewer and on the server, like an incident log timestamp or anything server-rendered; without it the server markup depends on the server zone.',
+ },
+ {
+ guidance: true,
+ description:
+ 'Label every entry once a tooltip shows more than one zone; a bare abbreviation is not always recognizable (Tokyo renders as "GMT+9", not "JST").',
+ },
+ {
+ guidance: true,
+ description:
+ 'Use isLive for active dashboards or real-time feeds so the relative time stays accurate without a page refresh.',
+ },
+ {
+ guidance: true,
+ description:
+ 'Reach for tooltipEntries when readers need to grab an exact value: an incident log or deploy record where someone pastes the UTC time or Unix seconds elsewhere; configuring entries turns the hover into copy-to-clipboard rows.',
+ },
+ {
+ guidance: false,
+ description:
+ "Don't display raw Unix timestamps or ISO strings to users; always pass them through Timestamp to get a human-readable format.",
+ },
+ {
+ guidance: false,
+ description:
+ 'Avoid system_date or system_time formats in user-facing UI; they are meant for developer tools, logs, and machine-readable contexts.',
+ },
+ {
+ guidance: false,
+ description:
+ 'Don\'t disable the hover card on relative timestamps; users expect to hover for the full date when they see "3 hours ago".',
+ },
+ {
+ guidance: false,
+ description:
+ "Don't stack many zones into one card; it is capped at 300px wide and long labelled lines wrap. Two or three entries read well.",
+ },
+ {
+ guidance: false,
+ description:
+ 'Don\'t pass a fixed-offset abbreviation like "EST" as timezoneID; it is a valid identifier but never observes daylight saving, so it reads an hour wrong for half the year. Use the region id, "America/New_York".',
+ },
],
anatomy: [
- {name: 'Formatted text', required: true, description: 'The rendered date, time, or relative label like "2 hours ago" or "Mar 21, 2025".'},
- {name: 'Hover card', required: false, description: 'A copyable hover card showing the full absolute date and time when the display is relative, or the rows configured via tooltipEntries. Its default single row carries the full absolute time.'},
- {name: 'Hover card row', required: false, description: 'One row of the card: an optional label beside the instant rendered in one time zone and format. Rows opt into a copy button via isCopyable.'},
- {name: 'Copy button', required: true, description: 'Per-row copy-to-clipboard button in the hover card; copies that row\'s formatted value.'},
+ {
+ name: 'Formatted text',
+ required: true,
+ description:
+ 'The rendered date, time, or relative label like "2 hours ago" or "Mar 21, 2025".',
+ },
+ {
+ name: 'Hover card',
+ required: false,
+ description:
+ 'A copyable hover card showing the full absolute date and time when the display is relative, or the rows configured via tooltipEntries. Its default single row carries the full absolute time.',
+ },
+ {
+ name: 'Hover card row',
+ required: false,
+ description:
+ 'One row of the card: an optional label beside the instant rendered in one time zone and format. Rows opt into a copy button via isCopyable.',
+ },
+ {
+ name: 'Copy button',
+ required: true,
+ description:
+ "Per-row copy-to-clipboard button in the hover card; copies that row's formatted value.",
+ },
],
},
};
@@ -140,15 +230,20 @@ export const docs = {
/** @type {import('@astryxdesign/cli/authoring').ComponentTranslationDoc} */
export const docsZh = {
propDescriptions: {
- value: '\u8981\u663e\u793a\u7684\u65e5\u671f/\u65f6\u95f4\u3002\u63a5\u53d7 Unix \u65f6\u95f4\u6233\uff08\u79d2\uff09\u6216 ISO 8601 \u5b57\u7b26\u4e32\u3002',
- format: "\u663e\u793a\u683c\u5f0f\u3002'relative' \u663e\u793a '2\u5c0f\u65f6\u524d'\uff0c'date' \u663e\u793a\u65e5\u671f\uff0c'date_long' \u663e\u793a\u957f\u6708\u4efd\u65e5\u671f\uff0c'date_weekday' \u663e\u793a\u661f\u671f+\u65e5\u671f\uff0c'auto' \u6839\u636e\u65f6\u95f4\u8fdc\u8fd1\u81ea\u52a8\u5207\u6362\u3002\u5e26\u65e5\u671f\u7684\u683c\u5f0f\uff08'date'\u3001'date_long'\u3001'date_weekday'\u3001'date_time'\uff0c\u4ee5\u53ca\u60ac\u505c\u5361\u7247\u548c\u65e0\u969c\u788d\u540d\u79f0\u4e2d\u7684\u5b8c\u6574\u65e5\u671f\uff09\u4f7f\u7528 InternationalizationProvider \u7684\u5386\u6cd5\uff08\u5982 calendar=\"persian\"\uff09\uff1b'time'\u3001\u76f8\u5bf9\u683c\u5f0f\u3001'system_*' \u548c 'unix_seconds' \u4e0d\u53d8\u3002",
- autoThreshold: "auto \u683c\u5f0f\u4ece\u76f8\u5bf9\u65f6\u95f4\u5207\u6362\u5230 date_time \u7684\u9608\u503c\u79d2\u6570\u3002",
- hasTooltip: '\u60ac\u505c\u65f6\u662f\u5426\u663e\u793a\u5305\u542b\u5b8c\u6574\u65e5\u671f/\u65f6\u95f4\u7684\u53ef\u590d\u5236\u60ac\u505c\u5361\u7247\uff08\u76f8\u5bf9\u65f6\u95f4\u6a21\u5f0f\uff0c\u6216\u914d\u7f6e tooltipEntries \u7684\u4efb\u610f\u683c\u5f0f\uff09\u3002',
+ value:
+ '\u8981\u663e\u793a\u7684\u65e5\u671f/\u65f6\u95f4\u3002\u63a5\u53d7 Unix \u65f6\u95f4\u6233\uff08\u79d2\uff09\u6216 ISO 8601 \u5b57\u7b26\u4e32\u3002',
+ format:
+ "\u663e\u793a\u683c\u5f0f\u3002'relative' \u663e\u793a '2\u5c0f\u65f6\u524d'\uff0c'date' \u663e\u793a\u65e5\u671f\uff0c'date_long' \u663e\u793a\u957f\u6708\u4efd\u65e5\u671f\uff0c'date_weekday' \u663e\u793a\u661f\u671f+\u65e5\u671f\uff0c'auto' \u6839\u636e\u65f6\u95f4\u8fdc\u8fd1\u81ea\u52a8\u5207\u6362\u3002\u5e26\u65e5\u671f\u7684\u683c\u5f0f\uff08'date'\u3001'date_long'\u3001'date_weekday'\u3001'date_time'\uff0c\u4ee5\u53ca\u60ac\u505c\u5361\u7247\u548c\u65e0\u969c\u788d\u540d\u79f0\u4e2d\u7684\u5b8c\u6574\u65e5\u671f\uff09\u4f7f\u7528 InternationalizationProvider \u7684\u5386\u6cd5\uff08\u5982 calendar=\"persian\"\uff09\uff1b'time'\u3001\u76f8\u5bf9\u683c\u5f0f\u3001'system_*' \u548c 'unix_seconds' \u4e0d\u53d8\u3002",
+ autoThreshold:
+ 'auto \u683c\u5f0f\u4ece\u76f8\u5bf9\u65f6\u95f4\u5207\u6362\u5230 date_time \u7684\u9608\u503c\u79d2\u6570\u3002',
+ hasTooltip:
+ '\u60ac\u505c\u65f6\u662f\u5426\u663e\u793a\u5305\u542b\u5b8c\u6574\u65e5\u671f/\u65f6\u95f4\u7684\u53ef\u590d\u5236\u60ac\u505c\u5361\u7247\uff08\u76f8\u5bf9\u65f6\u95f4\u6a21\u5f0f\uff0c\u6216\u914d\u7f6e tooltipEntries \u7684\u4efb\u610f\u683c\u5f0f\uff09\u3002',
tooltipEntries:
- '\u60ac\u505c\u65f6\u8981\u663e\u793a\u7684\u884c\uff0c\u7528\u4e8e\u540c\u65f6\u5c55\u793a\u591a\u4e2a\u65f6\u533a\u548c/\u6216\u591a\u79cd\u683c\u5f0f\u3002\u6bcf\u9879\u4e3a\u4e00\u884c\uff0c\u6309\u987a\u5e8f\u6e32\u67d3\uff1b\u7701\u7565 timezoneID\uff08\u6216\u4f20\u5165 \'local\'\uff09\u8868\u793a\u67e5\u770b\u8005\u672c\u5730\u65f6\u533a\u3002\u60ac\u505c\u9762\u677f\u59cb\u7ec8\u662f\u53ef\u9010\u884c\u590d\u5236\u5230\u526a\u8d34\u677f\u7684\u4ea4\u4e92\u5f0f\u5361\u7247\uff0c\u8fd9\u4e9b\u914d\u7f6e\u9879\u81ea\u5b9a\u4e49\u5176\u884c\uff1b\u672a\u914d\u7f6e\u65f6\u5361\u7247\u663e\u793a\u4e00\u884c\u9ed8\u8ba4\u7684\u5b8c\u6574\u7edd\u5bf9\u65f6\u95f4\u3002\u914d\u7f6e\u540e\u7edd\u5bf9\u65f6\u95f4\u683c\u5f0f\u4e5f\u4f1a\u56e0\u6b64\u83b7\u5f97\u60ac\u505c\u9762\u677f\u3002',
+ "\u60ac\u505c\u65f6\u8981\u663e\u793a\u7684\u884c\uff0c\u7528\u4e8e\u540c\u65f6\u5c55\u793a\u591a\u4e2a\u65f6\u533a\u548c/\u6216\u591a\u79cd\u683c\u5f0f\u3002\u6bcf\u9879\u4e3a\u4e00\u884c\uff0c\u6309\u987a\u5e8f\u6e32\u67d3\uff1b\u7701\u7565 timezoneID \u8868\u793a\u6cbf\u7528 Timestamp \u7684 timezoneID\uff08\u672a\u8bbe\u7f6e\u65f6\u4e3a\u67e5\u770b\u8005\u672c\u5730\u65f6\u533a\uff09\uff0c\u4f20\u5165 'local' \u5219\u59cb\u7ec8\u8868\u793a\u67e5\u770b\u8005\u672c\u5730\u65f6\u533a\u3002\u60ac\u505c\u9762\u677f\u59cb\u7ec8\u662f\u53ef\u9010\u884c\u590d\u5236\u5230\u526a\u8d34\u677f\u7684\u4ea4\u4e92\u5f0f\u5361\u7247\uff0c\u8fd9\u4e9b\u914d\u7f6e\u9879\u81ea\u5b9a\u4e49\u5176\u884c\uff1b\u672a\u914d\u7f6e\u65f6\u5361\u7247\u663e\u793a\u4e00\u884c\u9ed8\u8ba4\u7684\u5b8c\u6574\u7edd\u5bf9\u65f6\u95f4\u3002\u914d\u7f6e\u540e\u7edd\u5bf9\u65f6\u95f4\u683c\u5f0f\u4e5f\u4f1a\u56e0\u6b64\u83b7\u5f97\u60ac\u505c\u9762\u677f\u3002",
isTimezoneShown:
'\u662f\u5426\u5728\u53ef\u89c1\u6587\u672c\u540e\u9644\u52a0\u65f6\u533a\u7f29\u5199\uff08\u4ec5 date_time \u548c time\uff1bsystem_* \u683c\u5f0f\u4e0d\u9644\u52a0\uff09\u3002',
- isLive: '\u76f8\u5bf9\u65f6\u95f4\u662f\u5426\u5b9e\u65f6\u66f4\u65b0\u3002',
+ isLive:
+ '\u76f8\u5bf9\u65f6\u95f4\u662f\u5426\u5b9e\u65f6\u66f4\u65b0\u3002',
type: '\u6765\u81ea Text \u7684\u8bed\u4e49\u6587\u672c\u7c7b\u578b\u3002',
size: '\u663e\u5f0f\u5b57\u4f53\u5927\u5c0f\u8986\u76d6\u3002',
color: '\u6587\u5b57\u989c\u8272\u3002',
@@ -158,56 +253,178 @@ export const docsZh = {
description:
'Timestamp formats a date or time value into human-readable text. Use it to show when something was created, updated, or is scheduled; picking relative for recency, absolute for precision, or auto to let the component decide.',
bestPractices: [
- {guidance: true, description: 'Use the auto format in feeds and lists so recent items show "2 hours ago" and older items show the full date automatically.'},
- {guidance: true, description: 'Keep formatting consistent within the same list or table; mixing relative and absolute timestamps in the same column confuses scanning.'},
- {guidance: true, description: 'Enable isTimezoneShown when the audience spans multiple time zones, like a global team calendar or audit log.'},
- {guidance: true, description: 'Use tooltipEntries when readers must compare zones, such as an incident log where the reader\'s time and the event\'s origin zone both matter.'},
- {guidance: true, description: 'Label every entry once a tooltip shows more than one zone; a bare abbreviation is not always recognizable (Tokyo renders as "GMT+9", not "JST").'},
- {guidance: true, description: 'Use isLive for active dashboards or real-time feeds so the relative time stays accurate without a page refresh.'},
- {guidance: true, description: 'Reach for tooltipEntries when readers need to grab an exact value: an incident log or deploy record where someone pastes the UTC time or Unix seconds elsewhere; configuring entries turns the hover into copy-to-clipboard rows.'},
- {guidance: false, description: 'Don\'t display raw Unix timestamps or ISO strings to users; always pass them through Timestamp to get a human-readable format.'},
- {guidance: false, description: 'Avoid system_date or system_time formats in user-facing UI; they are meant for developer tools, logs, and machine-readable contexts.'},
- {guidance: false, description: 'Don\'t disable the hover card on relative timestamps; users expect to hover for the full date when they see "3 hours ago".'},
- {guidance: false, description: 'Don\'t stack many zones into one card; it is capped at 300px wide and long labelled lines wrap. Two or three entries read well.'},
- {guidance: false, description: 'Don\'t pass a fixed-offset abbreviation like "EST" as timezoneID; it is a valid identifier but never observes daylight saving, so it reads an hour wrong for half the year. Use the region id, "America/New_York".'},
+ {
+ guidance: true,
+ description:
+ 'Use the auto format in feeds and lists so recent items show "2 hours ago" and older items show the full date automatically.',
+ },
+ {
+ guidance: true,
+ description:
+ 'Keep formatting consistent within the same list or table; mixing relative and absolute timestamps in the same column confuses scanning.',
+ },
+ {
+ guidance: true,
+ description:
+ 'Enable isTimezoneShown when the audience spans multiple time zones, like a global team calendar or audit log.',
+ },
+ {
+ guidance: true,
+ description:
+ "Use tooltipEntries when readers must compare zones, such as an incident log where the reader's time and the event's origin zone both matter.",
+ },
+ {
+ guidance: true,
+ description:
+ 'Pass timezoneID when an absolute time must read the same for every viewer and on the server, like an incident log timestamp or anything server-rendered; without it the server markup depends on the server zone.',
+ },
+ {
+ guidance: true,
+ description:
+ 'Label every entry once a tooltip shows more than one zone; a bare abbreviation is not always recognizable (Tokyo renders as "GMT+9", not "JST").',
+ },
+ {
+ guidance: true,
+ description:
+ 'Use isLive for active dashboards or real-time feeds so the relative time stays accurate without a page refresh.',
+ },
+ {
+ guidance: true,
+ description:
+ 'Reach for tooltipEntries when readers need to grab an exact value: an incident log or deploy record where someone pastes the UTC time or Unix seconds elsewhere; configuring entries turns the hover into copy-to-clipboard rows.',
+ },
+ {
+ guidance: false,
+ description:
+ "Don't display raw Unix timestamps or ISO strings to users; always pass them through Timestamp to get a human-readable format.",
+ },
+ {
+ guidance: false,
+ description:
+ 'Avoid system_date or system_time formats in user-facing UI; they are meant for developer tools, logs, and machine-readable contexts.',
+ },
+ {
+ guidance: false,
+ description:
+ 'Don\'t disable the hover card on relative timestamps; users expect to hover for the full date when they see "3 hours ago".',
+ },
+ {
+ guidance: false,
+ description:
+ "Don't stack many zones into one card; it is capped at 300px wide and long labelled lines wrap. Two or three entries read well.",
+ },
+ {
+ guidance: false,
+ description:
+ 'Don\'t pass a fixed-offset abbreviation like "EST" as timezoneID; it is a valid identifier but never observes daylight saving, so it reads an hour wrong for half the year. Use the region id, "America/New_York".',
+ },
],
anatomy: [
- {name: 'Formatted text', required: true, description: 'The rendered date, time, or relative label like "2 hours ago" or "Mar 21, 2025".'},
- {name: 'Hover card', required: false, description: 'A copyable hover card showing the full absolute date and time when the display is relative, or the rows configured via tooltipEntries. Its default single row carries the full absolute time.'},
- {name: 'Hover card row', required: false, description: 'One row of the card: an optional label beside the instant rendered in one time zone and format. Rows opt into a copy button via isCopyable.'},
- {name: 'Copy button', required: true, description: 'Per-row copy-to-clipboard button in the hover card; copies that row\'s formatted value.'},
+ {
+ name: 'Formatted text',
+ required: true,
+ description:
+ 'The rendered date, time, or relative label like "2 hours ago" or "Mar 21, 2025".',
+ },
+ {
+ name: 'Hover card',
+ required: false,
+ description:
+ 'A copyable hover card showing the full absolute date and time when the display is relative, or the rows configured via tooltipEntries. Its default single row carries the full absolute time.',
+ },
+ {
+ name: 'Hover card row',
+ required: false,
+ description:
+ 'One row of the card: an optional label beside the instant rendered in one time zone and format. Rows opt into a copy button via isCopyable.',
+ },
+ {
+ name: 'Copy button',
+ required: true,
+ description:
+ "Per-row copy-to-clipboard button in the hover card; copies that row's formatted value.",
+ },
],
},
};
/** @type {import('@astryxdesign/cli/authoring').ComponentTranslationDoc} */
export const docsDense = {
- description: 'formatted timestamp with relative/absolute/auto modes, live updates, timezone display, and a copyable multi-zone hover card (default single full-time row, customized via tooltipEntries)',
+ description:
+ 'formatted timestamp with relative/absolute/auto modes, live updates, timezone display, and a copyable multi-zone hover card (default single full-time row, customized via tooltipEntries)',
usage: {
description:
'Timestamp formats a date or time into readable text. Use for creation dates, update times, or schedules; relative for recency, absolute for precision, auto to switch automatically.',
bestPractices: [
- {guidance: true, description: 'Auto format in feeds and lists; recent shows relative, older shows date_time.'},
- {guidance: true, description: 'Consistent formatting within the same list or table column.'},
- {guidance: true, description: 'isTimezoneShown for multi-timezone audiences.'},
- {guidance: true, description: 'tooltipEntries to compare zones when the reader time and event zone both matter.'},
- {guidance: true, description: 'Label each entry once a tooltip shows more than one zone; a bare abbreviation is not always recognizable (Tokyo renders "GMT+9", not "JST").'},
- {guidance: true, description: 'isLive for dashboards so relative time stays current.'},
- {guidance: true, description: 'tooltipEntries when readers must grab an exact value: an incident log or deploy record where someone pastes the UTC time or Unix seconds; entries turn the hover into copy-to-clipboard rows.'},
- {guidance: false, description: 'Don\'t show raw Unix timestamps or ISO strings; always use Timestamp.'},
- {guidance: false, description: 'Avoid system_* formats in user-facing UI; those are for dev tools and logs.'},
- {guidance: false, description: 'Don\'t disable the hover card on relative timestamps; users expect the full date on hover.'},
- {guidance: false, description: 'Don\'t stack many zones in one card; it caps at 300px and long labels wrap. Two or three read well.'},
- {guidance: false, description: 'Don\'t use fixed-offset ids like "EST" for timezoneID; they skip DST. Use region ids like "America/New_York".'},
+ {
+ guidance: true,
+ description:
+ 'Auto format in feeds and lists; recent shows relative, older shows date_time.',
+ },
+ {
+ guidance: true,
+ description:
+ 'Consistent formatting within the same list or table column.',
+ },
+ {
+ guidance: true,
+ description: 'isTimezoneShown for multi-timezone audiences.',
+ },
+ {
+ guidance: true,
+ description:
+ 'tooltipEntries to compare zones when the reader time and event zone both matter.',
+ },
+ {
+ guidance: true,
+ description:
+ 'Label each entry once a tooltip shows more than one zone; a bare abbreviation is not always recognizable (Tokyo renders "GMT+9", not "JST").',
+ },
+ {
+ guidance: true,
+ description: 'isLive for dashboards so relative time stays current.',
+ },
+ {
+ guidance: true,
+ description:
+ 'tooltipEntries when readers must grab an exact value: an incident log or deploy record where someone pastes the UTC time or Unix seconds; entries turn the hover into copy-to-clipboard rows.',
+ },
+ {
+ guidance: false,
+ description:
+ "Don't show raw Unix timestamps or ISO strings; always use Timestamp.",
+ },
+ {
+ guidance: false,
+ description:
+ 'Avoid system_* formats in user-facing UI; those are for dev tools and logs.',
+ },
+ {
+ guidance: false,
+ description:
+ "Don't disable the hover card on relative timestamps; users expect the full date on hover.",
+ },
+ {
+ guidance: false,
+ description:
+ "Don't stack many zones in one card; it caps at 300px and long labels wrap. Two or three read well.",
+ },
+ {
+ guidance: false,
+ description:
+ 'Don\'t use fixed-offset ids like "EST" for timezoneID; they skip DST. Use region ids like "America/New_York".',
+ },
],
},
propDescriptions: {
value: 'date/time as unix seconds or ISO string',
- format: "display mode: 'relative' (locale-native long wording), 'relative_short' (locale-native narrow wording), 'auto', 'date', 'date_long', 'date_weekday', 'date_time', 'time', 'system_date', 'system_date_time', 'system_time', 'unix_seconds'; date-bearing formats use the provider calendar, system_* and time do not",
+ format:
+ "display mode: 'relative' (locale-native long wording), 'relative_short' (locale-native narrow wording), 'auto', 'date', 'date_long', 'date_weekday', 'date_time', 'time', 'system_date', 'system_date_time', 'system_time', 'unix_seconds'; date-bearing formats use the provider calendar, system_* and time do not",
autoThreshold: 'seconds threshold for auto relative\u2192date_time switch',
- hasTooltip: 'show copyable full-time hover card on hover (relative mode, or any format with tooltipEntries)',
+ hasTooltip:
+ 'show copyable full-time hover card on hover (relative mode, or any format with tooltipEntries)',
tooltipEntries:
- "hover rows across zones/formats: [{timezoneID?, format?, label?}]; timezoneID omitted or 'local' = viewer zone, format defaults to 'full'; the hover surface is always a copy-to-clipboard card, these customize its rows (default: a single full-time row), and configuring entries enables the card on absolute formats",
+ "hover rows across zones/formats: [{timezoneID?, format?, label?}]; an entry without timezoneID follows the Timestamp timezoneID when set, else the viewer zone ('local' always means the viewer zone), format defaults to 'full'; the hover surface is always a copy-to-clipboard card, these customize its rows (default: a single full-time row), and configuring entries enables the card on absolute formats",
isTimezoneShown:
'append timezone abbreviation to visible text (date_time and time only)',
isLive: 'live-update relative time',
diff --git a/packages/core/src/Timestamp/Timestamp.test.tsx b/packages/core/src/Timestamp/Timestamp.test.tsx
index 134a077051..66617cb216 100644
--- a/packages/core/src/Timestamp/Timestamp.test.tsx
+++ b/packages/core/src/Timestamp/Timestamp.test.tsx
@@ -877,6 +877,38 @@ describe('Timestamp', () => {
expect(normalize(card.textContent ?? '')).toContain(normalize(expected));
});
+ it('keeps the default hover-card row in the viewer zone with timezoneID set', async () => {
+ const user = userEvent.setup();
+ const originalTZ = process.env.TZ;
+ process.env.TZ = 'UTC';
+ try {
+ render(
+ <Timestamp
+ value={new Date('2026-03-25T10:00:00Z').getTime() / 1000}
+ format="relative"
+ timezoneID="Asia/Tokyo"
+ data-testid="ts"
+ />,
+ );
+ const el = screen.getByTestId('ts');
+ await user.tab();
+ expect(el).toHaveFocus();
+ await waitFor(() => {
+ expect(HTMLElement.prototype.showPopover).toHaveBeenCalled();
+ });
+ const card = screen.getByRole('dialog', {hidden: true});
+ // FR7: the default row reads the viewer's zone, not the pinned one.
+ expect(card.textContent).toContain('10:00:00');
+ expect(card.textContent).not.toContain('19:00:00');
+ } finally {
+ if (originalTZ === undefined) {
+ delete process.env.TZ;
+ } else {
+ process.env.TZ = originalTZ;
+ }
+ }
+ });
+
it('does not add a tab stop when the hover card is disabled', () => {
render(
<Timestamp
@@ -1662,6 +1694,16 @@ describe('Timestamp server rendering', () => {
vi.useRealTimers();
});
+ const originalTZ = process.env.TZ;
+
+ afterEach(() => {
+ if (originalTZ === undefined) {
+ delete process.env.TZ;
+ } else {
+ process.env.TZ = originalTZ;
+ }
+ });
+
it.each(['date', 'date_time', 'time', 'unix_seconds'] as const)(
'never reads the current time for the absolute %s format',
format => {
@@ -1716,16 +1758,6 @@ describe('Timestamp server rendering', () => {
});
describe('across time zones', () => {
- const originalTZ = process.env.TZ;
-
- afterEach(() => {
- if (originalTZ === undefined) {
- delete process.env.TZ;
- } else {
- process.env.TZ = originalTZ;
- }
- });
-
it('writes the same server markup whatever the server time zone', () => {
const element = (
<Timestamp value="2026-03-25T10:00:00Z" format="relative" />
@@ -1791,6 +1823,145 @@ describe('Timestamp server rendering', () => {
host.remove();
}
});
+
+ it('renders an explicit time zone identically whatever the host zone', () => {
+ // Oct 15 in UTC, Oct 14 in Los Angeles: without the prop the host zone
+ // decides which day renders.
+ const element = (
+ <Timestamp
+ value={1665792474000}
+ format="date"
+ timezoneID="UTC"
+ hasTooltip={false}
+ />
+ );
+ process.env.TZ = 'UTC';
+ const utc = renderToString(element);
+ expect(utc).toContain('Oct 15, 2022');
+ process.env.TZ = 'America/Los_Angeles';
+ expect(renderToString(element)).toBe(utc);
+ process.env.TZ = 'Asia/Tokyo';
+ expect(renderToString(element)).toBe(utc);
+ });
+
+ it('shifts the reading into the named zone', () => {
+ process.env.TZ = 'UTC';
+ const {rerender} = render(
+ <Timestamp
+ value={1665792474000}
+ format="date"
+ timezoneID="America/Los_Angeles"
+ hasTooltip={false}
+ />,
+ );
+ expect(screen.getByText('Oct 14, 2022')).toBeInTheDocument();
+ rerender(
+ <Timestamp
+ value={1665792474000}
+ format="date"
+ timezoneID="Asia/Tokyo"
+ hasTooltip={false}
+ />,
+ );
+ expect(screen.getByText('Oct 15, 2022')).toBeInTheDocument();
+ });
+
+ it('hydrates explicit-zone server markup from another host zone without a mismatch', () => {
+ const element = (
+ <Timestamp
+ value={1665792474000}
+ format="date_time"
+ timezoneID="UTC"
+ hasTooltip={false}
+ />
+ );
+ process.env.TZ = 'UTC';
+ const host = document.createElement('div');
+ document.body.appendChild(host);
+ host.innerHTML = renderToString(element);
+
+ process.env.TZ = 'America/Los_Angeles';
+ const errors = vi.spyOn(console, 'error').mockImplementation(() => {});
+ let root: Root | undefined;
+ try {
+ act(() => {
+ root = hydrateRoot(host, element, {
+ onRecoverableError: error => {
+ throw error;
+ },
+ });
+ });
+ expect(host.textContent).toContain('Oct 15, 2022');
+ expect(errors).not.toHaveBeenCalled();
+ } finally {
+ errors.mockRestore();
+ act(() => root?.unmount());
+ host.remove();
+ }
+ });
+
+ it('keeps the UTC-labelled placeholder for a relative format with timezoneID', () => {
+ // FR3/ORD1: while the clock is pending the server placeholder is UTC
+ // with its label, whatever `timezoneID` pins.
+ const element = (
+ <Timestamp
+ value={new Date('2026-03-25T10:00:00Z').getTime() / 1000}
+ format="relative"
+ timezoneID="America/Los_Angeles"
+ hasTooltip={false}
+ />
+ );
+ process.env.TZ = 'America/Los_Angeles';
+ const html = renderToString(element);
+ expect(html).toContain('UTC');
+ expect(html).not.toContain('PDT');
+ });
+
+ it('ignores timezoneID in the relative accessible name', () => {
+ const value = Date.now() / 1000 - 3600;
+ const {rerender} = render(
+ <Timestamp
+ value={value}
+ format="relative"
+ hasTooltip={false}
+ data-testid="ts"
+ />,
+ );
+ const viewerLabel = screen.getByTestId('ts').getAttribute('aria-label');
+ rerender(
+ <Timestamp
+ value={value}
+ format="relative"
+ timezoneID="Asia/Tokyo"
+ hasTooltip={false}
+ data-testid="ts"
+ />,
+ );
+ expect(screen.getByTestId('ts').getAttribute('aria-label')).toBe(
+ viewerLabel,
+ );
+ });
+
+ it('falls back to the viewer zone on an unknown time zone', () => {
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ try {
+ process.env.TZ = 'UTC';
+ render(
+ <Timestamp
+ value={1665792474000}
+ format="date"
+ timezoneID="Never/Whence"
+ hasTooltip={false}
+ />,
+ );
+ expect(screen.getByText('Oct 15, 2022')).toBeInTheDocument();
+ expect(warn).toHaveBeenCalledWith(
+ expect.stringContaining('Never/Whence'),
+ );
+ } finally {
+ warn.mockRestore();
+ }
+ });
});
describe('Timestamp calendar systems', () => {
diff --git a/packages/core/src/Timestamp/Timestamp.tsx b/packages/core/src/Timestamp/Timestamp.tsx
index f5f91c3636..9f0f16f5a7 100644
--- a/packages/core/src/Timestamp/Timestamp.tsx
+++ b/packages/core/src/Timestamp/Timestamp.tsx
@@ -36,7 +36,7 @@ import type {BaseProps} from '../BaseProps';
import {themeProps} from '../utils/themeProps';
import {formatInstant, formatZoneName} from './formatInstant';
import {formatRelativeTime} from './formatRelativeTime';
-import {formatTooltipLines} from './tooltipEntries';
+import {formatTooltipLines, resolveTimezoneID} from './tooltipEntries';
import type {
TimestampTooltipEntry,
TimestampTooltipLine,
@@ -98,6 +98,17 @@ export interface TimestampProps extends BaseProps<HTMLTimeElement> {
* @default 'auto'
*/
format?: TimestampFormat;
+ /**
+ * IANA time zone the absolute formats render in, such as `'UTC'` or
+ * `'America/Los_Angeles'`. Omit (or pass `'local'`) for the viewer's own
+ * zone. An explicit zone renders identically on the server and the client,
+ * so it is the way to show an absolute time without a hydration mismatch;
+ * without it the server markup depends on the server's zone. Relative
+ * formats name no instant, so their visible text ignores it. Configured
+ * `tooltipEntries` rows still follow it. An unknown identifier warns once
+ * in development and falls back to the viewer's zone.
+ */
+ timezoneID?: string;
/**
* Threshold in seconds for 'auto' format to switch from relative to date_time.
* @default 604800 (7 days)
@@ -121,6 +132,10 @@ export interface TimestampProps extends BaseProps<HTMLTimeElement> {
* is copyable. With no entries the card shows a single default row with the
* full absolute time in the viewer's own zone, which is copyable.
*
+ * An entry without its own `timezoneID` follows the Timestamp's
+ * `timezoneID` when set, else the viewer's zone; `'local'` always means
+ * the viewer's zone.
+ *
* Configuring entries also attaches the surface to absolute formats, which
* otherwise have no hover card at all. `hasTooltip={false}` still suppresses
* it, and an empty array is treated as no configuration.
@@ -280,6 +295,7 @@ function isRelativeFormat(
export function Timestamp({
value,
format = 'auto',
+ timezoneID: timezoneIDProp,
autoThreshold = DEFAULT_AUTO_THRESHOLD,
hasTooltip = true,
tooltipEntries,
@@ -346,9 +362,10 @@ export function Timestamp({
: 'date_time'
: format;
- // Format the display text in the viewer's own zone; only the tooltip names
- // others. The one exception is the pre-hydration placeholder, written in
- // UTC with its label so every zone produces the same markup.
+ // Absolute text uses `timezoneID`, else the viewer's zone. A named zone makes
+ // the text the same on the server and the client. It does not reach the UTC
+ // placeholder, the default card row or the relative name.
+ const timezoneID = resolveTimezoneID(timezoneIDProp, 'timezoneID');
const displayText = !isValidDate
? ''
: effectiveFormat === 'relative'
@@ -360,24 +377,26 @@ export function Timestamp({
date,
effectiveFormat,
locale,
- // The placeholder before hydration is Gregorian and in UTC, with
- // its zone. The server and the client then write the same text,
- // with or without Temporal.
+ // The pre-hydration placeholder is Gregorian and in UTC, with its zone,
+ // whatever `timezoneID` pins. The server and the client then write the
+ // same text, with or without Temporal.
isClockPending
? {timeZone: 'UTC', isTimezoneShown: true}
- : {isTimezoneShown, calendar},
+ : {timeZone: timezoneID, isTimezoneShown, calendar},
)
: '';
// Full absolute text for the tooltip (visible — keeps the compact timezone
// abbreviation) and for the AT-facing aria-label, which spells the timezone
// out in full: abbreviations like "PST" or "GMT+2" are unexpanded
- // abbreviations to a screen-reader user (WCAG 3.1.4).
+ // abbreviations to a screen-reader user (WCAG 3.1.4). Both stay in the
+ // viewer's zone: the default hover-card row and the relative accessible name.
const fullAbsoluteText = isValidDate
- ? formatInstant(date, 'full', locale, {calendar})
+ ? formatInstant(date, 'full', locale, {timeZone: undefined, calendar})
: '';
const ariaLabelText = isValidDate
? formatInstant(date, 'full', locale, {
+ timeZone: undefined,
timeZoneNameStyle: 'long',
calendar,
})
@@ -435,7 +454,7 @@ export function Timestamp({
isCopyable: true,
},
]
- : formatTooltipLines(date, entries, locale, calendar);
+ : formatTooltipLines(date, entries, locale, calendar, timezoneID);
const timestampProps = mergeProps(
themeProps('timestamp', {format: effectiveFormat}),
diff --git a/packages/core/src/Timestamp/tooltipEntries.test.ts b/packages/core/src/Timestamp/tooltipEntries.test.ts
index ecdcc5704b..4ed99f628b 100644
--- a/packages/core/src/Timestamp/tooltipEntries.test.ts
+++ b/packages/core/src/Timestamp/tooltipEntries.test.ts
@@ -21,7 +21,15 @@ import {formatTooltipLines as formatTooltipLinesForLocale} from './tooltipEntrie
const formatTooltipLines = (
date: Parameters<typeof formatTooltipLinesForLocale>[0],
entries: Parameters<typeof formatTooltipLinesForLocale>[1],
-) => formatTooltipLinesForLocale(date, entries, 'en-US');
+ defaultTimezoneID?: Parameters<typeof formatTooltipLinesForLocale>[4],
+) =>
+ formatTooltipLinesForLocale(
+ date,
+ entries,
+ 'en-US',
+ 'gregory',
+ defaultTimezoneID,
+ );
/** 2026-02-19T17:00:00Z — chosen so several zones land on different dates. */
const INSTANT = new Date('2026-02-19T17:00:00Z');
@@ -77,6 +85,46 @@ describe('formatTooltipLines', () => {
expect(summer[0].value).toBe('2026-07-15 13:00:00');
});
+ // A pinned default outside the host zone: on a UTC host (like CI) a 'UTC'
+ // default would pass even without inheritance, and on a Tokyo host Tokyo
+ // would. Sydney is daylight (+11) through February, so the instant below
+ // reads 04:00 on the 20th.
+ const PINNED =
+ LOCAL_ZONE === 'Asia/Tokyo' ? 'Australia/Sydney' : 'Asia/Tokyo';
+ const PINNED_SYSTEM_DATE_TIME =
+ PINNED === 'Asia/Tokyo' ? '2026-02-20 02:00:00' : '2026-02-20 04:00:00';
+
+ it('lets entries without a zone inherit the Timestamp timezoneID', () => {
+ const lines = formatTooltipLines(
+ INSTANT,
+ [{format: 'system_date_time'}],
+ PINNED,
+ );
+ expect(lines).toHaveLength(1);
+ expect(lines[0].value).toBe(PINNED_SYSTEM_DATE_TIME);
+ });
+
+ it('keeps an explicit local entry in the viewer zone under a default', () => {
+ const [local, named] = formatTooltipLines(
+ INSTANT,
+ [
+ {timezoneID: 'local', format: 'system_date_time'},
+ {timezoneID: LOCAL_ZONE, format: 'system_date_time'},
+ ],
+ PINNED,
+ );
+ expect(local.value).toBe(named.value);
+ });
+
+ it('counts the pinned zone when labelling a viewer-zone row', () => {
+ const entries = [{timezoneID: 'local', format: 'date_time'}] as const;
+ const [labelled] = formatTooltipLines(INSTANT, [...entries], PINNED);
+ const [unlabelled] = formatTooltipLines(INSTANT, [...entries]);
+ // Next to pinned text the viewer-zone row carries its abbreviation; alone
+ // it reads like the page and stays unmarked.
+ expect(labelled.value).not.toBe(unlabelled.value);
+ });
+
// --- The shared date vocabulary ---
it.each(['date', 'date_long', 'date_weekday'] as const)(
diff --git a/packages/core/src/Timestamp/tooltipEntries.ts b/packages/core/src/Timestamp/tooltipEntries.ts
index 07763b13cb..34a3368a23 100644
--- a/packages/core/src/Timestamp/tooltipEntries.ts
+++ b/packages/core/src/Timestamp/tooltipEntries.ts
@@ -53,7 +53,8 @@ export type TimestampTooltipFormat = InstantFormat;
export interface TimestampTooltipEntry {
/**
* IANA time zone identifier, e.g. `'UTC'`, `'America/Los_Angeles'`.
- * Omit it — or pass `'local'` — for the viewer's own zone.
+ * Omit it to follow the Timestamp's `timezoneID` when set, else the
+ * viewer's own zone. Pass `'local'` for the viewer's own zone always.
*
* Prefer region identifiers. Fixed-offset abbreviations such as `'EST'` are
* accepted by the platform but never observe daylight saving, so they read
@@ -115,13 +116,16 @@ const LOCAL_ZONE_ALIAS = 'local';
const warnedTimezoneIDs = new Set<string>();
/**
- * Resolves an entry's zone to something safe to hand to `Intl`.
+ * Resolves a zone to something safe to hand to `Intl`.
*
* Returns `undefined` for the viewer's own zone, which is also what `Intl`
* treats as "use the host zone" — so the local path never constructs a
* formatter with an explicit `timeZone` and cannot drift from today's output.
*/
-function resolveTimezoneID(timezoneID: string | undefined): string | undefined {
+export function resolveTimezoneID(
+ timezoneID: string | undefined,
+ context: string = 'tooltipEntries',
+): string | undefined {
if (
timezoneID === undefined ||
timezoneID.toLowerCase() === LOCAL_ZONE_ALIAS
@@ -138,11 +142,12 @@ function resolveTimezoneID(timezoneID: string | undefined): string | undefined {
// validation path stays explicit and deterministic.
new Intl.DateTimeFormat('en-US', {timeZone: timezoneID});
} catch {
- if (!warnedTimezoneIDs.has(timezoneID)) {
- warnedTimezoneIDs.add(timezoneID);
+ const report = `${context}: ${timezoneID}`;
+ if (!warnedTimezoneIDs.has(report)) {
+ warnedTimezoneIDs.add(report);
devWarn(
'Timestamp',
- `unknown time zone ${JSON.stringify(timezoneID)} in tooltipEntries. Falling back to the viewer's time zone.`,
+ `unknown time zone ${JSON.stringify(timezoneID)} in ${context}. Falling back to the viewer's time zone.`,
);
}
return undefined;
@@ -204,16 +209,29 @@ function shouldShowZoneName(
* `calendar`.
*
* Pure: the same `date` and `entries` always produce the same lines for a given
- * host zone, locale, and calendar.
+ * host zone, locale, and calendar. Entries without their own `timezoneID` inherit
+ * `defaultTimezoneID` (already resolved); an explicit `'local'` still pins the
+ * viewer's zone.
*/
export function formatTooltipLines(
date: Date,
entries: ReadonlyArray<TimestampTooltipEntry>,
locale: Locale,
calendar: CalendarSystem = 'gregory',
+ defaultTimezoneID?: string,
): ReadonlyArray<TimestampTooltipLine> {
- const resolved = entries.map(entry => resolveTimezoneID(entry.timezoneID));
- const hasMultipleZones = new Set(resolved.map(zoneKey)).size > 1;
+ const resolved = entries.map(entry =>
+ entry.timezoneID === undefined
+ ? defaultTimezoneID
+ : resolveTimezoneID(entry.timezoneID),
+ );
+ // A pinned zone counts as one zone, so a viewer-zone row beside it shows
+ // its abbreviation.
+ const zoneKeys = new Set(resolved.map(zoneKey));
+ if (defaultTimezoneID !== undefined) {
+ zoneKeys.add(zoneKey(defaultTimezoneID));
+ }
+ const hasMultipleZones = zoneKeys.size > 1;
return entries.map((entry, index) => {
const format = entry.format ?? 'full';