Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(replay): show replay timestamps in the browser's hour cycle (#103322)

posthog[bot]d6dfb10475a8
diff --git a/frontend/src/lib/utils/datetime.test.ts b/frontend/src/lib/utils/datetime.test.ts
index 9f25fd68353e..2b04f754a2fa 100644
--- a/frontend/src/lib/utils/datetime.test.ts
+++ b/frontend/src/lib/utils/datetime.test.ts
@@ -5,6 +5,7 @@ import {
alignResolvedDateRangeToInterval,
formatDateTimeRange,
formatLocalizedDate,
+ formatLocalizedTime,
getConstrainedWeekRange,
getFormattedLastWeekDate,
parseDateInTimezone,
@@ -380,6 +381,45 @@ describe('datetime utils', () => {
})
})
+ describe('formatLocalizedTime', () => {
+ const originalLanguage = Object.getOwnPropertyDescriptor(window.navigator, 'language')
+ const originalLang = document.documentElement.lang
+
+ const setLanguage = (value: string | undefined): void => {
+ Object.defineProperty(window.navigator, 'language', { value, configurable: true })
+ }
+
+ afterEach(() => {
+ if (originalLanguage) {
+ Object.defineProperty(window.navigator, 'language', originalLanguage)
+ }
+ document.documentElement.lang = originalLang
+ })
+
+ it.each([
+ ['en-US', 'h:mm:ss A'],
+ ['en-AU', 'h:mm:ss A'],
+ ['en-GB', 'HH:mm:ss'],
+ ['de-DE', 'HH:mm:ss'],
+ ['fr-FR', 'HH:mm:ss'],
+ ])('returns the hour cycle of the %s locale', (language, expected) => {
+ setLanguage(language)
+ expect(formatLocalizedTime()).toBe(expected)
+ })
+
+ it('falls back to document.documentElement.lang when navigator.language is undefined', () => {
+ setLanguage(undefined)
+ // a 24-hour locale, so the assertion still fails if the fallback resolves to the en-US default
+ document.documentElement.lang = 'de-CH'
+ expect(formatLocalizedTime()).toBe('HH:mm:ss')
+ })
+
+ it('falls back to 24-hour rather than throwing on a malformed language tag', () => {
+ setLanguage('not a language tag')
+ expect(formatLocalizedTime()).toBe('HH:mm:ss')
+ })
+ })
+
describe('alignResolvedDateRangeToInterval', () => {
it('returns undefined when resolvedDateRange is missing', () => {
expect(alignResolvedDateRangeToInterval(undefined, 'month')).toBeUndefined()
diff --git a/frontend/src/lib/utils/datetime.ts b/frontend/src/lib/utils/datetime.ts
index 4c9ce016174f..f433752325e2 100644
--- a/frontend/src/lib/utils/datetime.ts
+++ b/frontend/src/lib/utils/datetime.ts
@@ -259,6 +259,27 @@ export function formatLocalizedDate(): string {
return usDateLocales.some((usLocale) => localLang.startsWith(usLocale)) ? 'MMM DD' : 'DD MMM'
}
+const localizedTimeFormats = new Map<string, string>()
+
+/** Wall-clock time format for the browser locale: 12-hour with AM/PM, or 24-hour. */
+export function formatLocalizedTime(): string {
+ const localLang = navigator.language || document.documentElement.lang || 'en-US'
+ // resolving the hour cycle costs tens of microseconds, and replay re-renders these labels every second
+ let format = localizedTimeFormats.get(localLang)
+ if (format === undefined) {
+ try {
+ // Intl knows the hour cycle of every locale, so no locale list has to be maintained here
+ const { hourCycle } = new Intl.DateTimeFormat(localLang, { hour: 'numeric' }).resolvedOptions()
+ format = hourCycle === 'h11' || hourCycle === 'h12' ? 'h:mm:ss A' : 'HH:mm:ss'
+ } catch {
+ // Intl rejects a malformed language tag, and 24-hour is the safe reading everywhere
+ format = 'HH:mm:ss'
+ }
+ localizedTimeFormats.set(localLang, format)
+ }
+ return format
+}
+
/** Parse a date string into a Dayjs in the given timezone, browser-tz-independent.
*
* - Strings without explicit timezone info ("2026-03-08", "2026-03-08 14:00:00")
diff --git a/frontend/src/scenes/session-recordings/components/ItemTimeDisplay.tsx b/frontend/src/scenes/session-recordings/components/ItemTimeDisplay.tsx
index c446d4c71cec..254336ffbda0 100644
--- a/frontend/src/scenes/session-recordings/components/ItemTimeDisplay.tsx
+++ b/frontend/src/scenes/session-recordings/components/ItemTimeDisplay.tsx
@@ -3,7 +3,7 @@ import { useValues } from 'kea'
import { Dayjs } from 'lib/dayjs'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { cn } from 'lib/utils/css-classes'
-import { formatLocalizedDate } from 'lib/utils/datetime'
+import { formatLocalizedDate, formatLocalizedTime } from 'lib/utils/datetime'
import { colonDelimitedDuration } from 'lib/utils/durations'
import { TimestampFormat } from '../player/playerSettingsLogic'
@@ -24,7 +24,7 @@ export function ItemTimeDisplay({
<div className={cn('px-2 py-1 text-xs min-w-18 text-center', className)}>
{timestampFormat !== TimestampFormat.Relative ? (
(timestampFormat === TimestampFormat.UTC ? timestamp.tz('UTC') : timestamp).format(
- `${formatLocalizedDate()}, HH:mm:ss`
+ `${formatLocalizedDate()}, ${formatLocalizedTime()}`
)
) : (
<>
diff --git a/frontend/src/scenes/session-recordings/components/SimpleTimeLabel.tsx b/frontend/src/scenes/session-recordings/components/SimpleTimeLabel.tsx
index fff38d3ccf3c..2a2196e12110 100644
--- a/frontend/src/scenes/session-recordings/components/SimpleTimeLabel.tsx
+++ b/frontend/src/scenes/session-recordings/components/SimpleTimeLabel.tsx
@@ -2,7 +2,7 @@ import clsx from 'clsx'
import { memo } from 'react'
import { Dayjs, dayjs } from 'lib/dayjs'
-import { formatLocalizedDate } from 'lib/utils/datetime'
+import { formatLocalizedDate, formatLocalizedTime } from 'lib/utils/datetime'
import { shortTimeZone } from 'lib/utils/timezones'
import { TimestampFormat } from 'scenes/session-recordings/player/playerSettingsLogic'
@@ -26,15 +26,16 @@ function formattedReplayTime(
}
function formatStringFor(d: Dayjs, timeOnly?: boolean): string {
+ const time = formatLocalizedTime()
if (timeOnly) {
- return 'HH:mm:ss'
+ return time
}
const today = dayjs()
if (d.isSame(today, 'year')) {
- return `${formatLocalizedDate()}, HH:mm:ss`
+ return `${formatLocalizedDate()}, ${time}`
}
- return `${formatLocalizedDate()} YYYY, HH:mm:ss`
+ return `${formatLocalizedDate()} YYYY, ${time}`
}
const truncateToSeconds = (time: string | number | Dayjs): number => {
diff --git a/frontend/src/scenes/session-recordings/player/controller/PlayerControllerTime.tsx b/frontend/src/scenes/session-recordings/player/controller/PlayerControllerTime.tsx
index adc17562dde0..3d16330aaf66 100644
--- a/frontend/src/scenes/session-recordings/player/controller/PlayerControllerTime.tsx
+++ b/frontend/src/scenes/session-recordings/player/controller/PlayerControllerTime.tsx
@@ -9,7 +9,7 @@ import { Dayjs, dayjs } from 'lib/dayjs'
import { useKeyHeld } from 'lib/hooks/useKeyHeld'
import { IconSkipBackward } from 'lib/lemon-ui/icons'
import { cn } from 'lib/utils/css-classes'
-import { formatLocalizedDate } from 'lib/utils/datetime'
+import { formatLocalizedDate, formatLocalizedTime } from 'lib/utils/datetime'
import { colonDelimitedDuration } from 'lib/utils/durations'
import { capitalizeFirstLetter } from 'lib/utils/strings'
import { shortTimeZone } from 'lib/utils/timezones'
@@ -35,7 +35,7 @@ function formatTimestampForTooltip(timestamp: number | undefined, format: Timest
return '--:--:--'
}
const d = format === TimestampFormat.UTC ? dayjs(timestamp).tz('UTC') : dayjs(timestamp)
- const formatted = d.format(`${formatLocalizedDate()}, HH:mm:ss`)
+ const formatted = d.format(`${formatLocalizedDate()}, ${formatLocalizedTime()}`)
const timezone = format === TimestampFormat.UTC ? 'UTC' : shortTimeZone(undefined, d.toDate())
return `${formatted} ${timezone}`
}
diff --git a/frontend/src/scenes/session-recordings/player/controller/PlayerSeekbarPreview.tsx b/frontend/src/scenes/session-recordings/player/controller/PlayerSeekbarPreview.tsx
index ee47e3e6ac09..49ccee5f7729 100644
--- a/frontend/src/scenes/session-recordings/player/controller/PlayerSeekbarPreview.tsx
+++ b/frontend/src/scenes/session-recordings/player/controller/PlayerSeekbarPreview.tsx
@@ -5,6 +5,7 @@ import { useDebouncedCallback } from 'use-debounce'
import { Dayjs } from 'lib/dayjs'
import useIsHovering from 'lib/hooks/useIsHovering'
import { cn } from 'lib/utils/css-classes'
+import { formatLocalizedTime } from 'lib/utils/datetime'
import { colonDelimitedDuration } from 'lib/utils/durations'
import { PlayerFrame } from '../PlayerFrame'
@@ -94,7 +95,9 @@ export const PlayerSeekbarPreview = memo(function PlayerSeekbarPreview({
timestampFormat === TimestampFormat.Relative
? colonDelimitedDuration(minMs / 1000 + progressionSeconds, fixedUnits)
: absoluteTime
- ? (timestampFormat === TimestampFormat.UTC ? absoluteTime?.tz('UTC') : absoluteTime)?.format('HH:mm:ss')
+ ? (timestampFormat === TimestampFormat.UTC ? absoluteTime?.tz('UTC') : absoluteTime)?.format(
+ formatLocalizedTime()
+ )
: '00:00:00'
const isHovering = useIsHovering(seekBarRef)
diff --git a/products/replay_vision/frontend/replay_scanners/components/ScannerAlertEventHistory.tsx b/products/replay_vision/frontend/replay_scanners/components/ScannerAlertEventHistory.tsx
index 39250bce4ba1..767848af3490 100644
--- a/products/replay_vision/frontend/replay_scanners/components/ScannerAlertEventHistory.tsx
+++ b/products/replay_vision/frontend/replay_scanners/components/ScannerAlertEventHistory.tsx
@@ -4,6 +4,7 @@ import { LemonButton, LemonTable, LemonTableColumns, LemonTag, LemonTagType } fr
import { TZLabel } from 'lib/components/TZLabel'
import { dayjs } from 'lib/dayjs'
+import { formatLocalizedTime } from 'lib/utils/datetime'
import {
AlertEvaluationHistoryChart,
@@ -81,7 +82,9 @@ function ScannerAlertEventTimeline({ alert }: { alert: VisionAlertConfigurationA
},
{
title: 'When',
- render: (_, event) => <TZLabel time={event.created_at} formatDate="MMM D" formatTime="HH:mm:ss" />,
+ render: (_, event) => (
+ <TZLabel time={event.created_at} formatDate="MMM D" formatTime={formatLocalizedTime()} />
+ ),
},
{
title: 'Detail',