photostructure / exiftool-vendored.js

Fast, cross-platform Node.js access to ExifTool
https://photostructure.github.io/exiftool-vendored.js/
MIT License
405 stars 37 forks source link

Wrong timezone offset is parsed from `TimeCreated` tag when using `inferTimezoneFromDatestamps` #157

Closed jrasm91 closed 9 months ago

jrasm91 commented 9 months ago

Describe the bug It looks like there is a bug in the logic to inferTimezoneFromDatestamps. Specifically, when set to true, the code will try to parse an offset from the CreateDateTagnames (from the raw tag values) and for some reason the implementation of extractOffset matches the hours/minutes in the TimeCreated tag.

To Reproduce

const { extractOffset } = require('exiftool-vendored/dist/Timezones');
const { ReadTask } = require('exiftool-vendored/dist/ReadTask');

console.log(
  ReadTask.for('/tmp/example.jpg', {
    inferTimezoneFromDatestamps: true,
  }).parse(
    JSON.stringify([
      {
        DateTimeOriginal: '2014:04:06 00:47:40',
        TimeCreated: '00:47:40+02:00',
        SourceFile: '/tmp/example.jpg',
      },
    ]),
  ),
);
// {
//   SourceFile: '/tmp/example.jpg',
//   errors: [],
//   tz: 'UTC+0:47',
//   tzSource: 'TimeCreated',
//   DateTimeOriginal: ExifDateTime {
//     year: 2014,
//     month: 4,
//     day: 6,
//     hour: 0,
//     minute: 47,
//     second: 40,
//     millisecond: undefined,
//     tzoffsetMinutes: 47,
//     rawValue: '2014:04:06 00:47:40',
//     zoneName: 'UTC+0:47',
//     inferredZone: undefined
//   },
//   TimeCreated: ExifTime {
//     hour: 18,
//     minute: 47,
//     second: 40,
//     millisecond: 0,
//     rawValue: '00:47:40+02:00'
//   }
// }

console.log(extractOffset('00:47:40+02:00'));
// { tz: 'UTC+0:47', src: 'offsetMinutesToZoneName' }

Expected behavior tz should be set to UTC+2

Environment (please complete the following information):

As always, thank you for the hard work on this great project!

daniele-athome commented 9 months ago

I reproduced the bug by adding IPTC date/time to an image already having EXIF date/time:

exiftool -IPTC:DateCreated="2019:07:24" -IPTC:TimeCreated="06:04:02" image_file.jpg
mceachen commented 9 months ago

Thanks for taking the time to make such a nice repro, @jrasm91 ! I'll get on this.

daniele-athome commented 9 months ago

Regarding my previous comment, please note that it might not only be about IPTC - see here. Anyway the repro might be all that is needed :-)

mceachen commented 9 months ago

Just released v23.1.0 :tada: