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.

fix(mobile): respect the device clock format (#129687)

Chris Volzer9f0ed783eade
diff --git a/products/mobile/docs/VIEWS.md b/products/mobile/docs/VIEWS.md
index a933453e280c..ba9462ed77f0 100644
--- a/products/mobile/docs/VIEWS.md
+++ b/products/mobile/docs/VIEWS.md
@@ -177,6 +177,8 @@ The dashboard, insight and web analytics screens (`app/views/dashboard/[id].tsx`
| Insight | The big number with its change pill, then the visual (`InsightVisual`) under a caption row with the full-screen button (`view-fullscreen`), ⓘ for "About this chart" (`view-about`). |
| Web analytics | The overview numbers in two columns, each with its change from the previous period. It always compares, as the web's overview tile does. |
+Chart clock times follow the device’s 12-hour or 24-hour preference, including hourly axes, tooltip headings, retention details and the “Data until” note. This changes only the display format; date ranges and bucket timezones keep their existing behavior.
+
A tap on a pinned tooltip opens the Point sheet (`point-sheet`): the bucket and every series value, "Watch recordings", "View people", "Open on web", "About this chart" and "Copy value".
People and recordings load through `usePointActors`, one `blocking` actors query at a time; closing the sheet drops a query that has not started. In demo, rows that open the web say "Not available in the demo".
An insight kind without a phone renderer shows "This chart opens on the web." `insightDisplay()` in `snapshotChart.ts` decides from the saved query, so a tile keeps its display while it loads; see [Kinds that still open the web](#kinds-that-still-open-the-web).
diff --git a/products/mobile/jest.setup.ts b/products/mobile/jest.setup.ts
index 10fee9c535b6..66ca62aadc28 100644
--- a/products/mobile/jest.setup.ts
+++ b/products/mobile/jest.setup.ts
@@ -1,5 +1,14 @@
import type { MetricChartProps } from '@/ui/chart/types'
+// Use a deterministic 12-hour device preference, matching the en-US locale in Expo's mock.
+jest.mock('expo-localization', () => {
+ const localization = jest.requireActual<typeof import('expo-localization')>('expo-localization')
+ return {
+ ...localization,
+ getCalendars: jest.fn(() => [{ ...localization.getCalendars()[0], uses24hourClock: false }]),
+ }
+})
+
jest.mock('expo-network', () => ({
...jest.requireActual<typeof import('expo-network')>('expo-network'),
addNetworkStateListener: jest.fn(() => ({ remove: jest.fn() })),
diff --git a/products/mobile/src/lib/dates.test.ts b/products/mobile/src/lib/dates.test.ts
new file mode 100644
index 000000000000..d75379b616fb
--- /dev/null
+++ b/products/mobile/src/lib/dates.test.ts
@@ -0,0 +1,39 @@
+import { getCalendars } from 'expo-localization'
+
+import { formatClock } from './dates'
+
+afterEach(() => {
+ jest.restoreAllMocks()
+ jest.mocked(getCalendars).mockReturnValue([{ ...getCalendars()[0], uses24hourClock: false }])
+})
+
+test.each<[boolean, number, number, string]>([
+ [false, 0, 3, '12:03 AM'],
+ [false, 9, 5, '9:05 AM'],
+ [false, 12, 0, '12:00 PM'],
+ [false, 16, 7, '4:07 PM'],
+ [true, 0, 3, '00:03'],
+ [true, 9, 5, '09:05'],
+ [true, 12, 0, '12:00'],
+ [true, 16, 7, '16:07'],
+])('formatClock with 24-hour preference %s at %s:%s returns %s', (uses24hourClock, hour, minute, expected) => {
+ jest.mocked(getCalendars).mockReturnValue([{ ...getCalendars()[0], uses24hourClock }])
+ expect(formatClock(new Date(2026, 9, 13, hour, minute))).toBe(expected)
+})
+
+test.each([
+ [true, '4:07 PM'],
+ [false, '16:07'],
+])('formatClock falls back to the browser hour12 preference %s', (hour12, expected) => {
+ jest.mocked(getCalendars).mockReturnValue([{ ...getCalendars()[0], uses24hourClock: null }])
+ const options = new Intl.DateTimeFormat().resolvedOptions()
+ jest.spyOn(Intl.DateTimeFormat.prototype, 'resolvedOptions').mockReturnValue({ ...options, hour12 })
+ expect(formatClock(new Date(2026, 9, 13, 16, 7))).toBe(expected)
+})
+
+test('formatClock reads a changed device preference on the next call', () => {
+ const date = new Date(2026, 9, 13, 16, 7)
+ expect(formatClock(date)).toBe('4:07 PM')
+ jest.mocked(getCalendars).mockReturnValue([{ ...getCalendars()[0], uses24hourClock: true }])
+ expect(formatClock(date)).toBe('16:07')
+})
diff --git a/products/mobile/src/lib/dates.ts b/products/mobile/src/lib/dates.ts
index 9d78f3ee15f8..b13bf4abb69d 100644
--- a/products/mobile/src/lib/dates.ts
+++ b/products/mobile/src/lib/dates.ts
@@ -1,4 +1,6 @@
-// Written by hand instead of with Intl so the output is identical in Hermes, the web build and Jest.
+import { getCalendars } from 'expo-localization'
+
+// Keep the English labels consistent across Hermes, the web build and Jest.
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] as const
const WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] as const
@@ -8,12 +10,19 @@ const MINUTE = 60_000
const HOUR = 60 * MINUTE
const DAY = 24 * HOUR
-export function formatClock(date: Date): string {
+export function prefers24HourClock(devicePreference: boolean | null = getCalendars()[0].uses24hourClock): boolean {
+ return devicePreference ?? Intl.DateTimeFormat(undefined, { hour: 'numeric' }).resolvedOptions().hour12 === false
+}
+
+export function formatClock(date: Date, uses24hourClock = prefers24HourClock()): string {
const hours = date.getHours()
- const minutes = date.getMinutes()
+ const minutes = String(date.getMinutes()).padStart(2, '0')
+ if (uses24hourClock) {
+ return `${String(hours).padStart(2, '0')}:${minutes}`
+ }
const hour12 = hours % 12 === 0 ? 12 : hours % 12
const suffix = hours < 12 ? 'AM' : 'PM'
- return `${hour12}:${String(minutes).padStart(2, '0')} ${suffix}`
+ return `${hour12}:${minutes} ${suffix}`
}
export function formatMonthDay(date: Date): string {
diff --git a/products/mobile/src/lib/useClockPreference.android.ts b/products/mobile/src/lib/useClockPreference.android.ts
new file mode 100644
index 000000000000..eb44b18e33a4
--- /dev/null
+++ b/products/mobile/src/lib/useClockPreference.android.ts
@@ -0,0 +1,17 @@
+import { useSyncExternalStore } from 'react'
+import { AppState } from 'react-native'
+
+import { prefers24HourClock } from './dates'
+
+function subscribe(onChange: () => void): () => void {
+ const subscription = AppState.addEventListener('change', (state) => {
+ if (state === 'active') {
+ onChange()
+ }
+ })
+ return () => subscription.remove()
+}
+
+export function useClockPreference(): boolean {
+ return useSyncExternalStore(subscribe, prefers24HourClock)
+}
diff --git a/products/mobile/src/lib/useClockPreference.ts b/products/mobile/src/lib/useClockPreference.ts
new file mode 100644
index 000000000000..9fc318ba8014
--- /dev/null
+++ b/products/mobile/src/lib/useClockPreference.ts
@@ -0,0 +1,8 @@
+import { useCalendars } from 'expo-localization'
+
+import { prefers24HourClock } from './dates'
+
+export function useClockPreference(): boolean {
+ const [calendar] = useCalendars()
+ return prefers24HourClock(calendar.uses24hourClock)
+}
diff --git a/products/mobile/src/ui/chart/MetricChartCanvas.test.tsx b/products/mobile/src/ui/chart/MetricChartCanvas.test.tsx
index daabe3f49c79..81425448ecd4 100644
--- a/products/mobile/src/ui/chart/MetricChartCanvas.test.tsx
+++ b/products/mobile/src/ui/chart/MetricChartCanvas.test.tsx
@@ -1,15 +1,44 @@
-import { fireEvent, render, screen } from '@testing-library/react-native'
+import { act, fireEvent, render, screen } from '@testing-library/react-native'
+import { getCalendars } from 'expo-localization'
+import { AppState } from 'react-native'
import 'react-native-gesture-handler/jestSetup'
import { MetricChartCanvas } from './MetricChartCanvas'
import type { ChartVariant } from './types'
jest.unmock('./MetricChartCanvas')
+jest.mock('@/lib/useClockPreference', () => jest.requireActual('@/lib/useClockPreference.android'))
jest.mock('react-native-worklets', () => jest.requireActual('react-native-worklets/src/mock'))
jest.mock('react-native-reanimated', () => jest.requireActual('react-native-reanimated/mock'))
jest.mock('./MetricChartRenderer', () => ({ MetricChartRenderer: () => null }))
describe('MetricChartCanvas', () => {
+ test('updates hourly axis labels when returning from Android clock settings', () => {
+ const calendar = getCalendars()[0]
+ render(
+ <MetricChartCanvas
+ kind="line"
+ accent="opportunity"
+ interval="hour"
+ label="Events"
+ formatValue={String}
+ points={[{ at: new Date(2026, 9, 13, 17).getTime(), value: 1 }]}
+ testID="metric"
+ />
+ )
+ fireEvent(screen.getByTestId('metric'), 'layout', { nativeEvent: { layout: { width: 320 } } })
+ expect(screen.getByText('5:00 PM')).toBeOnTheScreen()
+
+ jest.mocked(getCalendars).mockReturnValue([{ ...calendar, uses24hourClock: true }])
+ act(() => {
+ for (const [event, listener] of jest.mocked(AppState.addEventListener).mock.calls) {
+ if (event === 'change') listener('active')
+ }
+ })
+ expect(screen.getByText('17:00')).toBeOnTheScreen()
+ jest.mocked(getCalendars).mockReturnValue([calendar])
+ })
+
test.each<[ChartVariant, number | undefined, number, number]>([
['inline', undefined, 48, 100],
['inline', 240, 48, 196],
diff --git a/products/mobile/src/ui/chart/MetricChartCanvas.tsx b/products/mobile/src/ui/chart/MetricChartCanvas.tsx
index 461808f88ede..fe35908099bd 100644
--- a/products/mobile/src/ui/chart/MetricChartCanvas.tsx
+++ b/products/mobile/src/ui/chart/MetricChartCanvas.tsx
@@ -2,6 +2,7 @@ import { type ReactElement, useCallback, useMemo, useRef, useState } from 'react
import { type LayoutChangeEvent, Text, View } from 'react-native'
import type { PointsArray } from 'victory-native'
+import { useClockPreference } from '@/lib/useClockPreference'
import { createStyles, useTheme } from '@/ui/theme'
import { fonts } from '@/ui/tokens'
@@ -74,6 +75,7 @@ export function MetricChartCanvas(props: MetricChartProps): ReactElement {
accessibilityActions,
testID,
} = props
+ const uses24hourClock = useClockPreference()
const theme = useTheme()
const styles = useStyles()
const fullHeight = chartHeight(variant, props.height)
@@ -109,10 +111,11 @@ export function MetricChartCanvas(props: MetricChartProps): ReactElement {
count: totalCount,
values: axisValues,
dates: [],
+ uses24hourClock,
interval,
formatValue,
}),
- [width, fullHeight, kind, variant, totalCount, axisValues, interval, formatValue]
+ [width, fullHeight, kind, variant, totalCount, axisValues, interval, formatValue, uses24hourClock]
)
const pageSize = barPageSize(axisGeometry.plot.right - axisGeometry.plot.left, currentCount, barLayout)
const paged = kind === 'bar' && variant !== 'compact' && width > 0 && totalCount > pageSize
@@ -137,8 +140,19 @@ export function MetricChartCanvas(props: MetricChartProps): ReactElement {
const segments = useMemo(() => barSegments(visible, barLayout), [visible, barLayout])
const geometry = useMemo(() => {
- return chartGeometry({ width, height, kind, variant, count, values: axisValues, dates, interval, formatValue })
- }, [width, height, kind, variant, count, axisValues, dates, interval, formatValue])
+ return chartGeometry({
+ width,
+ height,
+ kind,
+ variant,
+ count,
+ values: axisValues,
+ dates,
+ interval,
+ formatValue,
+ uses24hourClock,
+ })
+ }, [width, height, kind, variant, count, axisValues, dates, interval, formatValue, uses24hourClock])
const plotted = useMemo<PlottedSeries[]>(
() =>
diff --git a/products/mobile/src/ui/chart/RetentionGrid.tsx b/products/mobile/src/ui/chart/RetentionGrid.tsx
index 96efc13cb387..fc3a0e177cdb 100644
--- a/products/mobile/src/ui/chart/RetentionGrid.tsx
+++ b/products/mobile/src/ui/chart/RetentionGrid.tsx
@@ -1,7 +1,8 @@
import { type ReactElement, useCallback, useState } from 'react'
import { ScrollView, Text, View } from 'react-native'
-import { formatMonthDay, parseBucketStart } from '@/lib/dates'
+import { formatClock, formatMonthDay, parseBucketStart } from '@/lib/dates'
+import { useClockPreference } from '@/lib/useClockPreference'
import { groupThousands, plural } from '@/model/adapters/text'
import type { RetentionCohortView, RetentionPeriodUnit, RetentionView } from '@/model/views'
import { Pressable44 } from '@/ui/Pressable44'
@@ -9,7 +10,7 @@ import { createStyles, useTheme } from '@/ui/theme'
import { lineHeight, type } from '@/ui/tokens'
import { useItemChartAccessibility } from './accessibility/useChartAccessibility'
-import { formatAxisDate, formatClockTime } from './chartMath'
+import { formatAxisDate } from './chartMath'
import { seriesColor } from './palette'
import { useItemSelection } from './selection/useItemSelection'
import type { ChartAccessibilityAction, ChartTrackingContext } from './types'
@@ -17,7 +18,7 @@ import type { ChartAccessibilityAction, ChartTrackingContext } from './types'
/** Periods a grid in a card shows. Full screen shows all of them. */
export const INLINE_RETENTION_PERIODS = 8
-const COHORT_WIDTH = 96
+const MIN_COHORT_WIDTH = 96
const CELL_WIDTH = 54
const CELL_HEIGHT = 34
const CELL_GAP = 2
@@ -35,10 +36,10 @@ interface RetentionGridProps {
}
/** The cohort's start in the project's wall-clock time, such as "Sep 13" or "Sep 2026". */
-export function cohortLabel(date: string, period: RetentionPeriodUnit): string {
+export function cohortLabel(date: string, period: RetentionPeriodUnit, uses24hourClock?: boolean): string {
if (period === 'hour') {
- const at = parseBucketStart(date.slice(0, 16).replace('T', ' '))
- return `${formatMonthDay(new Date(at))}, ${formatClockTime(at)}`
+ const at = new Date(parseBucketStart(date.slice(0, 16).replace('T', ' ')))
+ return `${formatMonthDay(at)}, ${formatClock(at, uses24hourClock)}`
}
return formatAxisDate(parseBucketStart(date.slice(0, 10)), period)
}
@@ -66,11 +67,16 @@ function cellShade(percent: number, base: string, card: string): { background: s
return { background: `rgb(${blend(1)}, ${blend(3)}, ${blend(5)})`, mix }
}
-function cohortSentence(cohort: RetentionCohortView, labels: readonly string[], period: RetentionPeriodUnit): string {
+function cohortSentence(
+ cohort: RetentionCohortView,
+ labels: readonly string[],
+ period: RetentionPeriodUnit,
+ uses24hourClock: boolean
+): string {
const cells = cohort.cells
.slice(1)
.map((cell, index) => `${labels[index + 1] ?? `Period ${index + 1}`} ${percentText(cell.percent)}`)
- const head = `${cohortLabel(cohort.date, period)} cohort, ${plural(cohort.size, 'person', 'people')}`
+ const head = `${cohortLabel(cohort.date, period, uses24hourClock)} cohort, ${plural(cohort.size, 'person', 'people')}`
return cells.length > 0 ? `${head}. ${cells.join(', ')}.` : `${head}.`
}
@@ -100,6 +106,7 @@ export function RetentionGrid({
}: RetentionGridProps): ReactElement {
const { colors, chartPalette, scheme } = useTheme()
const styles = useStyles()
+ const uses24hourClock = useClockPreference()
const base = seriesColor(0, chartPalette)
const { cohorts, period, periodLabels } = retention
const columns = periodLabels.slice(0, maxPeriods)
@@ -115,9 +122,9 @@ export function RetentionGrid({
const describe = useCallback(
(index: number) => {
const cohort = cohorts[index]
- return cohort ? cohortSentence(cohort, periodLabels, period) : ''
+ return cohort ? cohortSentence(cohort, periodLabels, period, uses24hourClock) : ''
},
- [cohorts, periodLabels, period]
+ [cohorts, periodLabels, period, uses24hourClock]
)
const mean = firstReturnMean(retention)
const a11y = useItemChartAccessibility({
@@ -176,7 +183,7 @@ export function RetentionGrid({
style={[styles.cohortDate, selection.selected === index && styles.cohortSelected]}
numberOfLines={1}
>
- {cohortLabel(cohort.date, period)}
+ {cohortLabel(cohort.date, period, uses24hourClock)}
</Text>
<Text style={styles.cohortSize} numberOfLines={1}>
{plural(cohort.size, 'person', 'people')}
@@ -234,7 +241,7 @@ export function RetentionGrid({
</View>
{pickedCohort && pickedCell && picked ? (
<Text style={styles.callout} testID={testID ? `${testID}-callout` : undefined}>
- {cohortLabel(pickedCohort.date, period)} cohort, {columns[picked.period]}:{' '}
+ {cohortLabel(pickedCohort.date, period, uses24hourClock)} cohort, {columns[picked.period]}:{' '}
{percentText(pickedCell.percent)}, {groupThousands(pickedCell.count)} of{' '}
{plural(
retention.reference === 'previous' && picked.period > 0
@@ -258,7 +265,7 @@ const useStyles = createStyles(({ colors }) => ({
flexDirection: 'row',
},
cohorts: {
- width: COHORT_WIDTH,
+ minWidth: MIN_COHORT_WIDTH,
paddingRight: 6,
},
cohort: {
diff --git a/products/mobile/src/ui/chart/chartGeometry.ts b/products/mobile/src/ui/chart/chartGeometry.ts
index d07eacb437ee..82dbe9dc2bf9 100644
--- a/products/mobile/src/ui/chart/chartGeometry.ts
+++ b/products/mobile/src/ui/chart/chartGeometry.ts
@@ -53,6 +53,7 @@ export interface GeometryInput {
values: number[]
dates: number[]
interval: ChartInterval
+ uses24hourClock: boolean
formatValue: (value: number) => string
}
@@ -106,7 +107,7 @@ export function chartGeometry(input: GeometryInput): ChartGeometry {
text: yTexts[index] ?? null,
}))
- const texts = dates.map((at) => formatAxisDate(at, interval))
+ const texts = dates.map((at) => formatAxisDate(at, interval, input.uses24hourClock))
const labelWidth = Math.max(0, ...texts.map((text) => monoTextWidth(text)))
const indices = compact
? count > 1
diff --git a/products/mobile/src/ui/chart/chartMath.test.ts b/products/mobile/src/ui/chart/chartMath.test.ts
index 6810d7fcfaae..c4c33dc06e17 100644
--- a/products/mobile/src/ui/chart/chartMath.test.ts
+++ b/products/mobile/src/ui/chart/chartMath.test.ts
@@ -1,3 +1,5 @@
+import { getCalendars } from 'expo-localization'
+
import { barPageSize, barSegments, barWindow } from './barLayout'
import { barSpan, yPosition } from './chartGeometry'
import {
@@ -14,6 +16,10 @@ import {
import type { ChartInterval, ChartKind, ChartSeries } from './types'
describe('chartMath', () => {
+ afterEach(() => {
+ jest.mocked(getCalendars).mockReturnValue([{ ...getCalendars()[0], uses24hourClock: false }])
+ })
+
test.each(['grouped', 'stacked'] as const)('bar windows cover every bucket at a readable width: %s', (layout) => {
const size = barPageSize(300, 6, layout)
const indices: number[] = []
@@ -104,7 +110,7 @@ describe('chartMath', () => {
})
test.each<[ChartInterval, string, string, string]>([
- ['hour', '09:05', 'Tue, Oct 13, 09:05', 'Oct 13, 09:05'],
+ ['hour', '9:05 AM', 'Tue, Oct 13, 9:05 AM', 'Oct 13, 9:05 AM'],
['day', 'Oct 13', 'Tue, Oct 13, 2026', 'Oct 13'],
['week', 'Oct 13', 'Oct 13 – 19, 2026', 'Oct 13'],
['month', 'Oct 2026', 'Oct 2026', 'Oct 2026'],
@@ -115,6 +121,18 @@ describe('chartMath', () => {
expect(formatPagerDate(at, interval)).toBe(pager)
})
+ test.each([
+ [false, '4:07 PM'],
+ [true, '16:07'],
+ ])('hourly chart labels follow the 24-hour preference %s', (uses24hourClock, clock) => {
+ jest.mocked(getCalendars).mockReturnValue([{ ...getCalendars()[0], uses24hourClock }])
+ const at = new Date(2026, 9, 13, 16, 7).getTime()
+ expect(formatPagerDate(at, 'hour')).toBe(`Oct 13, ${clock}`)
+ expect(formatAxisDate(at, 'hour')).toBe(clock)
+ expect(formatTooltipDate(at, 'hour', true)).toBe(clock)
+ expect(formatTooltipDate(at, 'hour')).toBe(`Tue, Oct 13, ${clock}`)
+ })
+
test.each<[string, Date, boolean, string]>([
['a week across months names both', new Date(2026, 8, 29), false, 'Sep 29 – Oct 5, 2026'],
['a week across years names both years', new Date(2026, 11, 28), false, 'Dec 28, 2026 – Jan 3, 2027'],
diff --git a/products/mobile/src/ui/chart/chartMath.ts b/products/mobile/src/ui/chart/chartMath.ts
index 4bcdd3652e23..2210de0a895f 100644
--- a/products/mobile/src/ui/chart/chartMath.ts
+++ b/products/mobile/src/ui/chart/chartMath.ts
@@ -1,4 +1,4 @@
-import { formatMonthDay, weekdayName } from '@/lib/dates'
+import { formatClock, formatMonthDay, weekdayName } from '@/lib/dates'
import type { ChartInterval, ChartKind, ChartPoint } from './types'
@@ -153,24 +153,16 @@ export function tooltipLeft(anchorX: number, tooltipWidth: number, containerWidt
return Math.min(maxLeft, Math.max(0, left))
}
-function pad2(value: number): string {
- return String(value).padStart(2, '0')
-}
-
-function clock24(date: Date): string {
- return `${pad2(date.getHours())}:${pad2(date.getMinutes())}`
-}
-
function monthYear(date: Date): string {
const [month] = formatMonthDay(date).split(' ')
return `${month} ${date.getFullYear()}`
}
-export function formatAxisDate(at: number, interval: ChartInterval): string {
+export function formatAxisDate(at: number, interval: ChartInterval, uses24hourClock?: boolean): string {
const date = new Date(at)
switch (interval) {
case 'hour':
- return clock24(date)
+ return formatClock(date, uses24hourClock)
case 'day':
case 'week':
return formatMonthDay(date)
@@ -212,7 +204,7 @@ export function formatTooltipDate(at: number, interval: ChartInterval, compact =
const date = new Date(at)
switch (interval) {
case 'hour':
- return compact ? clock24(date) : `${weekdayName(date)}, ${formatMonthDay(date)}, ${clock24(date)}`
+ return compact ? formatClock(date) : `${weekdayName(date)}, ${formatMonthDay(date)}, ${formatClock(date)}`
case 'day':
return compact
? `${weekdayName(date)}, ${formatMonthDay(date)}`
@@ -225,7 +217,7 @@ export function formatTooltipDate(at: number, interval: ChartInterval, compact =
}
export function formatClockTime(at: number): string {
- return clock24(new Date(at))
+ return formatClock(new Date(at))
}
/**
diff --git a/products/mobile/src/ui/chart/chartSeries.test.ts b/products/mobile/src/ui/chart/chartSeries.test.ts
index 0ecd0671a91b..93543ccf7885 100644
--- a/products/mobile/src/ui/chart/chartSeries.test.ts
+++ b/products/mobile/src/ui/chart/chartSeries.test.ts
@@ -1,3 +1,5 @@
+import { getCalendars } from 'expo-localization'
+
import { rangeContent, type TooltipContent, tooltipContent, tooltipPoint } from './chartSeries'
import type { ChartSeries } from './types'
@@ -32,6 +34,10 @@ const platforms: ChartSeries[] = ['iOS', 'Android', 'Web', 'Desktop', 'Watch'].m
}))
describe('chartSeries', () => {
+ afterEach(() => {
+ jest.mocked(getCalendars).mockReturnValue([{ ...getCalendars()[0], uses24hourClock: false }])
+ })
+
test.each<[string, ChartSeries[], string[], number, Partial<TooltipContent>]>([
[
'one series shows its previous period and the change',
@@ -45,7 +51,7 @@ describe('chartSeries', () => {
[current, previous],
[],
1,
- { header: 'Wed, Oct 14, 2026', note: 'In progress. Data until 14:32.' },
+ { header: 'Wed, Oct 14, 2026', note: 'In progress. Data until 2:32 PM.' },
],
['many series show the four highest and count the rest', platforms, [], 0, { more: 1, compare: null }],
['hidden series leave the tooltip', platforms, ['Watch', 'Desktop'], 0, { more: 0 }],
@@ -67,6 +73,25 @@ describe('chartSeries', () => {
expect(content.rows.some((row) => hidden.includes(row.key))).toBe(false)
})
+ test.each([
+ [false, '4:07 PM'],
+ [true, '16:07'],
+ ])('data freshness follows the 24-hour preference %s', (uses24hourClock, clock) => {
+ jest.mocked(getCalendars).mockReturnValue([{ ...getCalendars()[0], uses24hourClock }])
+ const point = tooltipPoint([current], [], 1, 'day')
+ if (!point) {
+ throw new Error('expected a point')
+ }
+ expect(
+ tooltipContent(point, {
+ formatValue: format,
+ compact: false,
+ maxRows: 4,
+ dataUntil: new Date(2026, 9, 14, 16, 7).getTime(),
+ }).note
+ ).toBe(`In progress. Data until ${clock}.`)
+ })
+
test('rangeContent puts the earlier marker first and skips the previous period', () => {
expect(rangeContent([current, previous], [], 1, 0, 'day', format)).toEqual({
header: 'Oct 13 → Oct 14',