Merge pull request #273 from kylmp/exif-timezone

# Conflicts:
#	app/tests/assetMetadata.test.ts
This commit is contained in:
Alan Grainger
2026-07-27 11:36:13 +12:00
11 changed files with 173 additions and 33 deletions
+1
View File
@@ -18,6 +18,7 @@
},
"exif": {
"dateTimeOriginal": false,
"timeZone": false,
"fileName": false,
"dimensions": false,
"fileSize": false,
+5
View File
@@ -525,8 +525,13 @@ html.ipp-sidebar-open .ipp-sidebar {
.ipp-sidebar-date {
padding: 12px 0;
}
.ipp-sidebar-date-primary {
font-weight: 500;
}
.ipp-sidebar-row-body .ipp-sidebar-date-secondary {
margin-bottom: 0;
}
.ipp-sidebar-coords {
font-size: 13px;
+1
View File
@@ -20,6 +20,7 @@ export const ICON_CLOSE = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fil
// Sidebar field rows (file / camera / lens / map)
export const ICON_IMAGE = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M8.5,13.5L11,16.5L14.5,12L19,18H5M21,19V5C21,3.89 20.1,3 19,3H5A2,2 0 0,0 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19Z"/></svg>'
export const ICON_CALENDAR = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M19,19H5V8H19M16,1V3H8V1H6V3H5C3.89,3 3,3.89 3,5V19C3,20.1 3.9,21 5,21H19C20.1,21 21,20.1 21,19V5C21,3.89 20.1,3 19,3H18V1M19,6H5V5H19V6Z"/></svg>'
export const ICON_CAMERA = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M4,4H7L9,2H15L17,4H20A2,2 0 0,1 22,6V18A2,2 0 0,1 20,20H4A2,2 0 0,1 2,18V6A2,2 0 0,1 4,4M12,7A5,5 0 0,0 7,12A5,5 0 0,0 12,17A5,5 0 0,0 17,12A5,5 0 0,0 12,7M12,9A3,3 0 0,1 15,12A3,3 0 0,1 12,15A3,3 0 0,1 9,12A3,3 0 0,1 12,9Z"/></svg>'
export const ICON_IRIS = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M13.73,15L9.83,21.76C10.53,21.91 11.25,22 12,22C14.4,22 16.6,21.15 18.32,19.75L14.66,13.4M2.46,15C3.38,17.92 5.61,20.26 8.45,21.34L12.12,15M8.54,12L4.64,5.25C3,7 2,9.39 2,12C2,12.68 2.07,13.35 2.2,14H9.69M21.8,10H14.31L14.6,10.5L19.36,18.75C21,16.97 22,14.6 22,12C22,11.31 21.93,10.64 21.8,10M21.54,9C20.62,6.07 18.39,3.74 15.55,2.66L11.88,9M9.4,10.5L14.17,2.24C13.47,2.09 12.75,2 12,2C9.6,2 7.4,2.84 5.68,4.25L9.34,10.6L9.4,10.5Z"/></svg>'
export const ICON_MAP = '<svg viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" d="M12,11.5A2.5,2.5 0 0,1 9.5,9A2.5,2.5 0 0,1 12,6.5A2.5,2.5 0 0,1 14.5,9A2.5,2.5 0 0,1 12,11.5M12,2A7,7 0 0,0 5,9C5,14.25 12,22 12,22C12,22 19,14.25 19,9A7,7 0 0,0 12,2Z"/></svg>'
+95 -18
View File
@@ -5,7 +5,7 @@
// by the toolbar info button or the `i` key, persisted via localStorage.
import { state, SIDEBAR_STORAGE_KEY } from './state.js'
import { ICON_INFO, ICON_CLOSE, ICON_IMAGE, ICON_CAMERA, ICON_IRIS, ICON_MAP } from './icons.js'
import { ICON_INFO, ICON_CLOSE, ICON_IMAGE, ICON_CALENDAR, ICON_CAMERA, ICON_IRIS, ICON_MAP } from './icons.js'
import type { GalleryItem, GalleryExif } from '../shared/types.js'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -200,7 +200,7 @@ function renderDetailRows (exif: GalleryExif): HTMLElement[] {
const rows: HTMLElement[] = [heading]
if (exif.dateTimeOriginal) {
rows.push(renderDateRow(exif.dateTimeOriginal))
rows.push(renderDateRow(exif.dateTimeOriginal, exif.timeZone))
}
const fileRow = renderFileRow(exif)
if (fileRow) rows.push(fileRow)
@@ -212,10 +212,21 @@ function renderDetailRows (exif: GalleryExif): HTMLElement[] {
return rows
}
function renderDateRow (iso: string): HTMLElement {
const row = document.createElement('div')
row.className = 'ipp-sidebar-row ipp-sidebar-date'
row.textContent = formatDate(iso)
function renderDateRow (iso: string, timeZone?: string): HTMLElement {
const row = makeRow(ICON_CALENDAR)
row.classList.add('ipp-sidebar-date')
const body = row.querySelector('.ipp-sidebar-row-body') as HTMLElement
const formatted = formatDate(iso, timeZone)
const date = document.createElement('p')
date.className = 'ipp-sidebar-date-primary'
date.textContent = formatted.date
body.appendChild(date)
if (formatted.time) {
const time = document.createElement('p')
time.className = 'ipp-sidebar-date-secondary'
time.textContent = formatted.time
body.appendChild(time)
}
return row
}
@@ -367,20 +378,86 @@ function hasAnyLocationField (exif: GalleryExif): boolean {
(exif.latitude != null && exif.longitude != null))
}
function formatDate (iso: string): string {
const d = new Date(iso)
if (isNaN(d.getTime())) return iso
try {
return new Intl.DateTimeFormat(undefined, {
const DATE_FORMAT_OPTIONS: Intl.DateTimeFormatOptions = {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: '2-digit'
}).format(d)
} catch (e) {
return iso
month: 'short',
day: 'numeric'
}
const TIME_FORMAT_OPTIONS: Intl.DateTimeFormatOptions = {
weekday: 'short',
hour: 'numeric',
minute: '2-digit',
second: '2-digit'
}
export interface FormattedDate {
date: string
time: string
}
export function formatDate (iso: string, timeZone?: string): FormattedDate {
const d = new Date(iso)
if (isNaN(d.getTime())) return { date: iso, time: '' }
if (timeZone) {
try {
return {
date: new Intl.DateTimeFormat(undefined, { ...DATE_FORMAT_OPTIONS, timeZone }).format(d),
time: new Intl.DateTimeFormat(undefined, {
...TIME_FORMAT_OPTIONS,
timeZone,
timeZoneName: 'longOffset'
}).format(d)
}
} catch (e) {
const offsetMinutes = parseFixedOffset(timeZone)
if (offsetMinutes != null) {
const localWallClock = new Date(d.getTime() + offsetMinutes * 60_000)
return {
date: new Intl.DateTimeFormat(undefined, { ...DATE_FORMAT_OPTIONS, timeZone: 'UTC' }).format(localWallClock),
time: new Intl.DateTimeFormat(undefined, { ...TIME_FORMAT_OPTIONS, timeZone: 'UTC' }).format(localWallClock) +
' ' + formatFixedOffset(offsetMinutes)
}
}
try {
return {
date: new Intl.DateTimeFormat(undefined, { ...DATE_FORMAT_OPTIONS, timeZone }).format(d),
time: new Intl.DateTimeFormat(undefined, { ...TIME_FORMAT_OPTIONS, timeZone }).format(d)
}
} catch (e) {
// Invalid/unknown timezone: retain the previous browser-local fallback.
}
}
}
try {
return {
date: new Intl.DateTimeFormat(undefined, DATE_FORMAT_OPTIONS).format(d),
time: new Intl.DateTimeFormat(undefined, TIME_FORMAT_OPTIONS).format(d)
}
} catch (e) {
return { date: iso, time: '' }
}
}
function parseFixedOffset (timeZone: string): number | null {
const match = /^(?:UTC|GMT)([+-])(\d{1,2})(?::?(\d{2}))?$/i.exec(timeZone.trim())
if (!match) return null
const hours = Number(match[2])
const minutes = Number(match[3] || 0)
if (hours > 14 || minutes > 59 || (hours === 14 && minutes !== 0)) return null
const total = hours * 60 + minutes
return match[1] === '-' ? -total : total
}
function formatFixedOffset (offsetMinutes: number): string {
const sign = offsetMinutes < 0 ? '-' : '+'
const absolute = Math.abs(offsetMinutes)
const hours = Math.floor(absolute / 60).toString().padStart(2, '0')
const minutes = (absolute % 60).toString().padStart(2, '0')
return `GMT${sign}${hours}:${minutes}`
}
export function formatBytes (bytes: number): string {
+11 -1
View File
@@ -67,7 +67,7 @@ export function displayDimensions (asset: Asset): { width?: number, height?: num
`enabled: true` users).
*/
const EXIF_FIELDS = [
'dateTimeOriginal', 'make', 'model', 'lensModel',
'make', 'model', 'lensModel',
'exposureTime', 'iso', 'fNumber', 'focalLength'
] as const
@@ -75,6 +75,16 @@ const LOCATION_FIELDS = ['city', 'state', 'country'] as const
const EXIF_RULES: FieldRule[] = [
...EXIF_FIELDS.map(copy),
{
flag: 'dateTimeOriginal',
emit: (out, info) => {
if (info.dateTimeOriginal) {
out.dateTimeOriginal = info.dateTimeOriginal
// Never expose the timezone independently of the opted-in date.
if (fieldFlag('exif', 'timeZone') && info.timeZone) out.timeZone = info.timeZone
}
}
},
{
flag: 'fileName',
emit: (out, _info, asset) => {
+1
View File
@@ -16,6 +16,7 @@ export type GroupByDateMode = 'month' | 'day'
export interface GalleryExif {
dateTimeOriginal?: string // ISO date string; client formats with Intl.DateTimeFormat
timeZone?: string
fileName?: string
width?: number
height?: number
+1
View File
@@ -20,6 +20,7 @@ export interface ExifInfo {
// Additional EXIF fields surfaced by Immich for the metadata sidebar
// (gated server-side by ipp.showMetadata.exif.* and .location.* config).
dateTimeOriginal?: string | null;
timeZone?: string | null;
fileSizeInByte?: number | null;
make?: string | null;
model?: string | null;
+15
View File
@@ -22,6 +22,8 @@ const asset = (): Asset => ({
originalMimeType: 'image/heic',
exifInfo: {
description: 'A nice photo',
dateTimeOriginal: '2025-10-18T06:28:54.000Z',
timeZone: 'Asia/Singapore',
make: 'Canon',
model: 'EOS R5',
city: 'Paris',
@@ -94,6 +96,19 @@ describe('buildAssetMetadata', () => {
expect(buildAssetMetadata(photo, share()).exif).toMatchObject({ width, height })
})
it('returns the photo timezone only when both date and timezone are enabled', () => {
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')
setConfig({ ipp: { showMetadata: { exif: { dateTimeOriginal: true } } } })
expect(buildAssetMetadata(asset(), share()).exif?.timeZone).toBeUndefined()
setConfig({ ipp: { showMetadata: { exif: { timeZone: true } } } })
expect(buildAssetMetadata(asset(), share()).exif).toBeUndefined()
})
it('returns description when a description surface is enabled', () => {
setConfig({ ipp: { showMetadata: { description: { sidebar: true } } } })
const meta = buildAssetMetadata(asset(), share())
+1
View File
@@ -186,6 +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.fileName).toBe(true)
expect(exif.dimensions).toBe(true)
expect(exif.fileSize).toBe(true)
+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: '' })
})
})
+5 -2
View File
@@ -13,6 +13,7 @@ Show the description in the sidebar only (not as a lightbox caption), expose cam
"description": { "caption": false, "sidebar": true },
"exif": {
"dateTimeOriginal": true,
"timeZone": true,
"make": true,
"model": true,
"lensModel": true,
@@ -39,7 +40,7 @@ Every per-field flag defaults to `false`. A field is sent to the client only whe
The share owner's **"Show metadata"** toggle in Immich takes precedence over everything here: when it's off, IPP suppresses all description / EXIF / location output and hides the info sidebar (and its toolbar toggle) entirely, regardless of these settings. Note that with "Show metadata" off Immich also strips file creation dates from non-album shares, so [date grouping](/config/gallery#groupbydate) won't work for those shares.
The info sidebar (and its toolbar toggle button) only appear when there is at least one section the operator has opted into - i.e. `description.sidebar` is true, or `exif` / `location` has at least one flag set to `true`. With all three off, the sidebar UI is suppressed.
The info sidebar (and its toolbar toggle button) only appear when there is at least one section the operator has opted into - i.e. `description.sidebar` is true, or `exif` / `location` has at least one displayable field set to `true`. Dependent flags such as `exif.timeZone` do not activate the sidebar on their own. With all three groups off, the sidebar UI is suppressed.
## Description
@@ -57,8 +58,9 @@ Set both to show in both places; set neither and the description is not included
Under `ipp.showMetadata.exif`. Every flag defaults to `false`.
| Option | Type | Description |
|--------------------|--------|-----------------------------------------------|
|--------------------|--------|------------------------------------------------------------------------------------------------------------------|
| `dateTimeOriginal` | `bool` | Show the date the photo was taken (per EXIF). |
| `timeZone` | `bool` | Show and use the photo's timezone when formatting the date. Only applies when `dateTimeOriginal` is also enabled. |
| `fileName` | `bool` | Show the original filename. |
| `dimensions` | `bool` | Show width x height and megapixel count. |
| `fileSize` | `bool` | Show the file size. |
@@ -93,6 +95,7 @@ Show the description in the sidebar only (not as a lightbox caption), expose cam
"description": { "caption": false, "sidebar": true },
"exif": {
"dateTimeOriginal": true,
"timeZone": true,
"make": true,
"model": true,
"lensModel": true,