From d973e9062a94ed862b974eca0ccf666ba626be0d Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Tue, 3 Nov 2026 00:45:56 +0100 Subject: [PATCH] fix: give a photo's date only from when it was taken, not when the file changed exif.test.ts: the case "falls back to the file date" now expects no date, since IFD0's DateTime is the file's change date, not the date the photo was taken. --- lib/__tests__/exif.test.ts | 4 ++-- lib/exif.ts | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/__tests__/exif.test.ts b/lib/__tests__/exif.test.ts index 31e4ddd88..2e18542e2 100644 --- a/lib/__tests__/exif.test.ts +++ b/lib/__tests__/exif.test.ts @@ -72,9 +72,9 @@ describe('readPhotoExif', () => { } }); - it('falls back to the file date when the original date is missing', () => { + it('gives no date when only the date the file changed is there', () => { const bytes = jpeg(tiff(false, { ifd0: [{ tag: 0x0132, type: 2, ascii: '2026:11:01 09:00:00' }], exif: [], gps: [] })); - expect(readPhotoExif(bytes)).toEqual({ taken: '2026-11-01T09:00:00' }); + expect(readPhotoExif(bytes)).toEqual({}); }); it('gives nothing for a JPEG without EXIF, a PNG or broken bytes', () => { diff --git a/lib/exif.ts b/lib/exif.ts index cde7a8bc4..4c5a0cf7c 100644 --- a/lib/exif.ts +++ b/lib/exif.ts @@ -12,7 +12,6 @@ export interface PhotoExif { const TAG_EXIF_IFD = 0x8769; const TAG_GPS_IFD = 0x8825; -const TAG_DATETIME = 0x0132; const TAG_DATETIME_ORIGINAL = 0x9003; const TAG_OFFSET_TIME_ORIGINAL = 0x9011; const GPS_LAT_REF = 1; @@ -126,8 +125,8 @@ export function readPhotoExif(data: ArrayBuffer | Uint8Array): PhotoExif { const ifd0 = tiff.ifd(tiff.firstIfd()); const exifAt = tiff.long(ifd0.get(TAG_EXIF_IFD)); const exif = exifAt ? tiff.ifd(exifAt) : new Map(); - const taken = exifDate(tiff.ascii(exif.get(TAG_DATETIME_ORIGINAL)), tiff.ascii(exif.get(TAG_OFFSET_TIME_ORIGINAL))) - ?? exifDate(tiff.ascii(ifd0.get(TAG_DATETIME)), undefined); + // Only the date the photo was taken: IFD0's DateTime is when the file was last changed. + const taken = exifDate(tiff.ascii(exif.get(TAG_DATETIME_ORIGINAL)), tiff.ascii(exif.get(TAG_OFFSET_TIME_ORIGINAL))); if (taken) out.taken = taken; const gpsAt = tiff.long(ifd0.get(TAG_GPS_IFD)); if (gpsAt) {