Compare commits

...

5 Commits

Author SHA1 Message Date
Christian Byrne
8214a8a94a Merge branch 'main' into bl/fix-qpo-system-time-format 2026-06-25 17:32:13 -07:00
Benjamin Lu
3da54d4526 refactor: drop unused clock preference plumbing from queue display
The clockPreferenceLocale param was threaded through BuildJobDisplayCtx and
buildQueuedTime but never populated by useJobList (its only caller), so it was
always undefined in production. formatClockTime already resolves the system
hour cycle from the runtime default locale when the preference is omitted, so
the queueDisplay threading and its forwarding-only test added no behavior.
2026-06-18 18:05:29 -07:00
Benjamin Lu
619b9ef8e2 test: cover 24-hour clock preference 2026-06-18 16:11:32 -07:00
Benjamin Lu
f7bfefde33 fix: forward queue time clock preference 2026-06-18 16:11:32 -07:00
Benjamin Lu
9b29705a6a fix: use system hour cycle for queue times 2026-06-18 16:11:31 -07:00
2 changed files with 55 additions and 6 deletions

View File

@@ -212,8 +212,44 @@ describe('formatShortMonthDay', () => {
describe('formatClockTime', () => {
it('formats time with hours, minutes, and seconds', () => {
const ts = new Date(2024, 5, 15, 14, 5, 6).getTime()
const hourCycle = new Intl.DateTimeFormat(undefined, {
hour: 'numeric'
}).resolvedOptions().hourCycle
const options = {
hour: 'numeric',
minute: '2-digit',
second: '2-digit',
hourCycle
} satisfies Intl.DateTimeFormatOptions
const expected = new Intl.DateTimeFormat('en-GB', options).format(ts)
const result = formatClockTime(ts, 'en-GB')
// en-GB uses 24-hour format
expect(result).toBe('14:05:06')
expect(result).toBe(expected)
})
it('uses app locale with explicit 12-hour preference', () => {
const ts = new Date(2024, 5, 15, 14, 5, 6).getTime()
const options = {
hour: 'numeric',
minute: '2-digit',
second: '2-digit',
hourCycle: 'h12'
} satisfies Intl.DateTimeFormatOptions
const expected = new Intl.DateTimeFormat('es', options).format(ts)
expect(formatClockTime(ts, 'es', 'en-US')).toBe(expected)
})
it('uses app locale with explicit 24-hour preference', () => {
const ts = new Date(2024, 5, 15, 14, 5, 6).getTime()
const options = {
hour: 'numeric',
minute: '2-digit',
second: '2-digit',
hourCycle: 'h23'
} satisfies Intl.DateTimeFormatOptions
const expected = new Intl.DateTimeFormat('es', options).format(ts)
expect(formatClockTime(ts, 'es', 'en-GB')).toBe(expected)
})
})

View File

@@ -84,17 +84,30 @@ export const formatShortMonthDay = (ts: number, locale: string): string => {
}
/**
* Localized clock time, e.g. "10:05:06" with locale defaults for 12/24 hour.
* Localized clock time, e.g. "10:05:06" with the app locale for language and
* the browser/system locale preference for 12/24-hour formatting.
*
* @param ts Unix timestamp in milliseconds
* @param locale BCP-47 locale string
* @param clockPreferenceLocale Optional locale source for hour-cycle preference
* @returns Localized time string
*/
export const formatClockTime = (ts: number, locale: string): string => {
export const formatClockTime = (
ts: number,
locale: string,
clockPreferenceLocale?: string
): string => {
const d = new Date(ts)
return new Intl.DateTimeFormat(locale, {
const hourCycle = new Intl.DateTimeFormat(clockPreferenceLocale, {
hour: 'numeric'
}).resolvedOptions().hourCycle
const options: Intl.DateTimeFormatOptions = {
hour: 'numeric',
minute: '2-digit',
second: '2-digit'
}).format(d)
}
if (hourCycle !== undefined) {
options.hourCycle = hourCycle
}
return new Intl.DateTimeFormat(locale, options).format(d)
}