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.
This commit is contained in:
Linus Rath
2026-11-03 00:45:56 +01:00
parent f7a7828bfa
commit d973e9062a
2 changed files with 4 additions and 5 deletions
+2 -2
View File
@@ -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', () => {
+2 -3
View File
@@ -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<number, Entry>();
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) {