#273 refinements: match Immich date display, fix timeline UTC parsing, rename timezone flag

This commit is contained in:
Alan Grainger
2026-07-27 12:14:19 +12:00
parent 4ba5c2eeee
commit f8c83bc1f4
13 changed files with 174 additions and 59 deletions
+2 -2
View File
@@ -97,7 +97,7 @@ describe('buildAssetMetadata', () => {
})
it('returns the photo timezone only when both date and timezone are enabled', () => {
setConfig({ ipp: { showMetadata: { exif: { dateTimeOriginal: true, timeZone: true } } } })
setConfig({ ipp: { showMetadata: { exif: { dateTimeOriginal: true, timezone: true } } } })
const meta = buildAssetMetadata(asset(), share())
expect(meta.exif?.dateTimeOriginal).toBe('2025-10-18T06:28:54.000Z')
expect(meta.exif?.timeZone).toBe('Asia/Singapore')
@@ -105,7 +105,7 @@ describe('buildAssetMetadata', () => {
setConfig({ ipp: { showMetadata: { exif: { dateTimeOriginal: true } } } })
expect(buildAssetMetadata(asset(), share()).exif?.timeZone).toBeUndefined()
setConfig({ ipp: { showMetadata: { exif: { timeZone: true } } } })
setConfig({ ipp: { showMetadata: { exif: { timezone: true } } } })
expect(buildAssetMetadata(asset(), share()).exif).toBeUndefined()
})
+46
View File
@@ -0,0 +1,46 @@
import { describe, it, expect, beforeAll, afterAll } from 'vitest'
import { localDateTimeFromOffset } from '../src/immich'
/*
Regression test for the timeline date-grouping skew: Immich's timeline
bucket API returns fileCreatedAt as a zone-less UTC string
('2024-12-11T07:41:54'), which Date.parse treats as server-local time.
On a non-UTC host every reconstructed localDateTime shifted by the
host's UTC offset, putting assets under the wrong date-group header
(e.g. a "10 Dec" header over photos whose sidebar said 11 Dec).
TZ is pinned to a far-from-UTC zone so the suite fails if the parse
ever becomes host-local again, regardless of the machine running it.
*/
const originalTz = process.env.TZ
beforeAll(() => {
process.env.TZ = 'Pacific/Auckland' // UTC+12/+13
})
afterAll(() => {
if (originalTz === undefined) delete process.env.TZ
else process.env.TZ = originalTz
})
describe('localDateTimeFromOffset', () => {
it('treats zone-less timeline timestamps as UTC, not server-local', () => {
expect(localDateTimeFromOffset('2024-12-11T07:41:54', 0)).toBe('2024-12-11T07:41:54.000Z')
})
it('applies the photographer offset to the UTC instant', () => {
expect(localDateTimeFromOffset('2024-12-10T15:30:00', 8)).toBe('2024-12-10T23:30:00.000Z')
expect(localDateTimeFromOffset('2024-12-11T03:30:00', -8)).toBe('2024-12-10T19:30:00.000Z')
})
it('leaves explicitly zoned timestamps alone', () => {
expect(localDateTimeFromOffset('2024-12-11T07:41:54Z', 0)).toBe('2024-12-11T07:41:54.000Z')
expect(localDateTimeFromOffset('2024-12-11T07:41:54+00:00', 0)).toBe('2024-12-11T07:41:54.000Z')
})
it('returns undefined for missing or invalid input', () => {
expect(localDateTimeFromOffset(undefined, 0)).toBeUndefined()
expect(localDateTimeFromOffset('not-a-date', 0)).toBeUndefined()
})
})
+1 -1
View File
@@ -186,7 +186,7 @@ describe('metadataEnabled shim', () => {
const exif = ((config.ipp as Record<string, unknown>).showMetadata as Record<string, unknown>).exif as Record<string, unknown>
expect(exif.enabled).toBeUndefined()
expect(exif.dateTimeOriginal).toBe(true)
expect(exif.timeZone).toBeUndefined()
expect(exif.timezone).toBeUndefined()
expect(exif.fileName).toBe(true)
expect(exif.dimensions).toBe(true)
expect(exif.fileSize).toBe(true)
+28 -4
View File
@@ -1,11 +1,14 @@
import { describe, expect, it } from 'vitest'
import { formatDate } from '../src/client/sidebar'
import { formatDate, formatWallClock } from '../src/client/sidebar'
// The locale is pinned to en-US throughout: formatDate follows the system
// locale by default, which would make these assertions machine-dependent.
describe('sidebar date formatting', () => {
const capturedAt = '2025-10-18T06:28:54.000Z'
it('formats the capture instant in the photo IANA timezone', () => {
const formatted = formatDate(capturedAt, 'Asia/Singapore')
const formatted = formatDate(capturedAt, 'Asia/Singapore', 'en-US')
expect(formatted.date).toBe('Oct 18, 2025')
expect(formatted.time).toContain('Sat')
expect(formatted.time).toContain('2:28:54 PM')
@@ -13,13 +16,34 @@ describe('sidebar date formatting', () => {
})
it('supports legacy fixed-offset timezones from Immich', () => {
const formatted = formatDate(capturedAt, 'UTC+8')
const formatted = formatDate(capturedAt, 'UTC+8', 'en-US')
expect(formatted.date).toBe('Oct 18, 2025')
expect(formatted.time).toContain('2:28:54 PM')
expect(formatted.time).toContain('GMT+08:00')
})
it('falls back to local formatting for an unknown timezone', () => {
const formatted = formatDate(capturedAt, 'Not/AZone', 'en-US')
expect(formatted.date).toMatch(/Oct 1[78], 2025/)
expect(formatted.time).toContain(':28:54')
})
it('retains the original value when the timestamp is invalid', () => {
expect(formatDate('not-a-date', 'Asia/Singapore')).toEqual({ date: 'not-a-date', time: '' })
expect(formatDate('not-a-date', 'Asia/Singapore', 'en-US')).toEqual({ date: 'not-a-date', time: '' })
})
})
describe('sidebar wall-clock formatting', () => {
// localDateTime carries the photographer's wall-clock with a nominal Z;
// it must render exactly as written, with no offset label, for any viewer.
it('renders the wall-clock as written with no offset label', () => {
const formatted = formatWallClock('2024-12-10T23:30:00.000Z', 'en-US')
expect(formatted.date).toBe('Dec 10, 2024')
expect(formatted.time).toContain('11:30:00 PM')
expect(formatted.time).not.toContain('GMT')
})
it('retains the original value when the timestamp is invalid', () => {
expect(formatWallClock('not-a-date', 'en-US')).toEqual({ date: 'not-a-date', time: '' })
})
})