Add date time with timezone offset option

This commit is contained in:
klymp
2026-07-26 16:54:12 +02:00
parent aa6183a95d
commit 1533d3de6d
11 changed files with 173 additions and 33 deletions
+25
View File
@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest'
import { formatDate } from '../src/client/sidebar'
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')
expect(formatted.date).toBe('Oct 18, 2025')
expect(formatted.time).toContain('Sat')
expect(formatted.time).toContain('2:28:54 PM')
expect(formatted.time).toContain('GMT+08:00')
})
it('supports legacy fixed-offset timezones from Immich', () => {
const formatted = formatDate(capturedAt, 'UTC+8')
expect(formatted.date).toBe('Oct 18, 2025')
expect(formatted.time).toContain('2:28:54 PM')
expect(formatted.time).toContain('GMT+08:00')
})
it('retains the original value when the timestamp is invalid', () => {
expect(formatDate('not-a-date', 'Asia/Singapore')).toEqual({ date: 'not-a-date', time: '' })
})
})