Skip to content

Fix tiff-reviver to adjust from local time to UTC #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

websocket98765
Copy link

@websocket98765 websocket98765 commented Dec 3, 2022

Goal is to fix this issue where Tiff-based formats revive an inaccurate date.

@websocket98765
Copy link
Author

websocket98765 commented Dec 5, 2022

I realized '2009-09-23 11:40:52-06:00' is a standard format so I can simply using the date object to parse it into UTC, when in this format. Updated the code.

@grasdk
Copy link

grasdk commented Feb 10, 2024

@websocket98765 I know this is over 1 year old and there is not much active going on with exifr. However @MikeKovarik seems to be active on github still. If Mike ever gets around to this PR, I would like to comment with another idea:

I'm afraid that the problem lies with using the Date object in the first place. The Date object has bad support for timezones and alsways assumes the local timezone or UTC time. If you have two pictures, one in Sydney and one in London taken at the exact same time, their MS representation would be the same but the offset different. The Date object would simply show the two pictures taken at the exact same timestamp UTC or your local time. There is no option to show the time with their correct offsets.

Therefore, my opinion / idea as that all dates should simply be returned as they are read from the exif sections. In string format if need be, or as a millisecond value and an offset. Then it would be up to the user of exifr to determine how to use the values in their code.

@chriscdn
Copy link

@grasdk I agree with your points. To further the discussion, I've written a small library to handle this case. It performs the following functions:

  • Extracts the latitude and longitude from the photo and, if available, determines the time zone.
  • Determines the UTC timestamp of the photo by using OffsetTimeOriginal or the time zone.

The function returns:

  • localTime – The original DateTimeOriginal string in ISO 8601 format (without time zone information).
  • timestamp – The Unix time of the photo.
  • timeZone – The time zone where the photo was taken.

With this information, photos can be correctly sorted regardless of where they were taken, and dates can be formatted locally or relative to any other time zone. Of course, your success will depend on what metadata is available with each photo.

I've also added some normalization since exifr seems to return different values for PNGs (at least those exported from Lightroom).

The package is available here if you're curious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DateTime not accurate (offset by n hours)
3 participants