Skip to content
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

DateTime not accurate (offset by n hours) #90

Open
DePasqualeOrg opened this issue Apr 19, 2022 · 4 comments · May be fixed by #99
Open

DateTime not accurate (offset by n hours) #90

DePasqualeOrg opened this issue Apr 19, 2022 · 4 comments · May be fixed by #99

Comments

@DePasqualeOrg
Copy link

I noticed that the datetimes exifr provides are offset by some number of hours from the correct time. The times provided by exifr are two hours before the local time where the photos were taken. Perhaps this is related to the fact that the time zone of the system I'm using to read the data is currently two hours ahead of GMT.

Here is the relevant data from a photo read by exifr:

ModifyDate: 2021-08-28T07:02:40.000Z
DateTimeOriginal: 2021-08-28T07:02:40.000Z
CreateDate: 2021-08-28T07:02:40.000Z

And with exif-reader (these are the correct local times):

ModifyDate: 2021-08-28T09:02:40.000Z
DateTimeOriginal: 2021-08-28T09:02:40.000Z
DateTimeDigitized: 2021-08-28T09:02:40.000Z
@mcdamo
Copy link

mcdamo commented Apr 28, 2022

Looks like a bug here:

// can be '2009-09-23 17:40:52 UTC' or '2010:07:06 20:45:12'
function reviveDate(string) {
if (typeof string !== 'string') return undefined
var [year, month, day, hours, minutes, seconds] = string.trim().split(/[-: ]/g).map(Number)
var date = new Date(year, month - 1, day)
if (!Number.isNaN(hours) && !Number.isNaN(minutes) && !Number.isNaN(seconds)) {
date.setHours(hours)
date.setMinutes(minutes)
date.setSeconds(seconds)
}
if (Number.isNaN(+date))
return string
else
return date
}

Should be using date.setUTC* functions here to avoid setting in the local timezone.

@websocket98765
Copy link

I'm also experiencing this date inaccuracy, with RAW files based on TIFF.

Here is what exifr returns

DateTimeOriginal: 2022-07-03T20:58:33.000Z, // inaccurate. This time is local, but Z indicates UTC. This should be 2022-07-04T02:58:33.000Z when using UTC.
CreateDate: 2022-07-03T20:58:33.000Z,       // inaccurate. This time is local, but Z indicates UTC. This should be 2022-07-04T02:58:33.000Z when using UTC.
OffsetTime: '-06:00', // accurate

For comparison, exiftool via CLI returns the following, which is all correct

Date Time Original: 2022:07:03 20:58:33-06:00
Create Date: 2022:07:03 20:58:33-06:00
Offset Time: -06:00

@websocket98765
Copy link

websocket98765 commented Jul 4, 2022

The fix may be to adjust the local time by the offset after creating the date object, by adding something like below after Line 57 in the tiff reviver and passing the offset into the reviveDate(string, offsetString). Example:

  const date = new Date(dateTimeOriginal);

  // Convert from string (e.g. -06:00) to number (e.g. -360)
  const offsetMin = Number(offsetString.split(':')[0]) * 60;
  // Change local time to UTC
  date.setMinutes(date.getMinutes() - offsetMin); 

In my experience, DateTimeOriginal is always in local time, so this works. But if you prefer the method to support UTC input as the comments indicate, then wrapping the setMinutes() in a conditional to not run when DateTimeOriginal is in UTC should do it:

  if (!isUTC)  { // pseudocode
      // Convert from string (e.g. -06:00) to number (e.g. -360)
      const offsetMin = Number(offsetString.split(':')[0]) * 60;
      // Change local time to UTC
      date.setMinutes(date.getMinutes() - offsetMin);
  }

@websocket98765
Copy link

websocket98765 commented Nov 29, 2022

@MikeKovarik I'd like to help solve this if you could guide how to get the datetime offset into the tiff river file please, because that seems to be the missing piece that would allow this code to be updated to convert the date object from local time to the correct UTC time.

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 a pull request may close this issue.

3 participants