ExifTool Forum

ExifTool => Developers => Topic started by: geoffblack on November 15, 2017, 12:46:41 PM

Title: Output all dates in UTC?
Post by: geoffblack on November 15, 2017, 12:46:41 PM
I've been using ExifTool for quite some time, launching from within a Python app. My question is whether there is an option I've missed that will make ExifTool output all dates in UTC? The reason I'm posting in this particular forum is that it's difficult to run acceptance tests in different timezones when ExifTool always uses the local system timezone to output dates.

As a specific example, for a particular executable, you'll get <EXE:TimeStamp>2017:04:18 02:18:23-04:00</EXE:TimeStamp> in Eastern and <EXE:TimeStamp>2017:04:18 01:18:23-05:00</EXE:TimeStamp> in Central.

I've tried messing around with -d, but that does not have an option for UTC output unless you want epoch time, which is not human-readable. Thanks!
Title: Re: Output all dates in UTC?
Post by: Phil Harvey on November 15, 2017, 01:01:29 PM
A quick work-around is to set your system timezone to UTC.  I'll think about whether there is another way...

- Phil
Title: Re: Output all dates in UTC?
Post by: Phil Harvey on November 15, 2017, 01:11:02 PM
OK, this hack should work on Mac/Linux:

exiftool -if 'require POSIX and $$ENV{TZ}="UTC" and POSIX::tzset(),1' ...

But with the Windows .exe version I'm not sure if tzset would be available. (Plus, you'd have to swap the quotes around)

- Phil
Title: Re: Output all dates in UTC?
Post by: Phil Harvey on November 15, 2017, 01:36:54 PM
I'll add a new API TimeZone option in ExifTool 10.67, so this will work for future versions:

exiftool -api timezone=UTC ...

- Phil
Title: Re: Output all dates in UTC?
Post by: geoffblack on November 15, 2017, 01:48:07 PM
QuoteI'll add a new API TimeZone option in ExifTool 10.67, so this will work for future versions: exiftool -api timezone=UTC ...

That would be fantastic, thank you. If will be a huge help to have all UTC output. tzset does not work with the Windows exe, from what I can see.
Title: Re: Output all dates in UTC?
Post by: Phil Harvey on November 15, 2017, 01:52:58 PM
Oops.  I may not be able to implement this in Windows if my hack didn't work.  :(

I'll look into this.

- Phil
Title: Re: Output all dates in UTC?
Post by: Phil Harvey on November 15, 2017, 02:00:56 PM
OK.  In Windows, run this command before running ExifTool:

set TZ=UTC

- Phil
Title: Re: Output all dates in UTC?
Post by: geoffblack on November 15, 2017, 02:34:17 PM
Ah, that's interesting. In Python, you can provide an environment to subprocess.Popen, so I can modify it without having to run a command. This looks good for the EXE:TimeStamp field. I'm guessing FlashPix:ModifyDate and ICC-header:ProfileDateTime in the cases below don't have any timezone info encoded, so those times aren't shifting, only the displayed timezone?


From: <EXE:TimeStamp>2017-04-18T02:18:23-0400</EXE:TimeStamp>
To:   <EXE:TimeStamp>2017-04-18T06:18:23+0000</EXE:TimeStamp>



From: <FlashPix:ModifyDate>2009-08-11T23:14:57-0400</FlashPix:ModifyDate>
To:   <FlashPix:ModifyDate>2009-08-11T23:14:57+0000</FlashPix:ModifyDate>



From: <ICC-header:ProfileDateTime>1998-02-09T06:49:00-0500</ICC-header:ProfileDateTime>
To:   <ICC-header:ProfileDateTime>1998-02-09T06:49:00+0000</ICC-header:ProfileDateTime>
Title: Re: Output all dates in UTC?
Post by: geoffblack on November 17, 2017, 10:40:41 AM
FYI confirmed that -api TimeZone=UTC in 10.67 does not work on Windows. Setting the environment variable TZ works great, though. Thanks, again.
Title: Re: Output all dates in UTC?
Post by: Phil Harvey on November 17, 2017, 11:14:51 AM
Quote from: geoffblack on November 17, 2017, 10:40:41 AM
FYI confirmed that -api TimeZone=UTC in 10.67 does not work on Windows.

Yes.  Unfortunately the ActivePerl doesn't support POSIX::tzset()

But at least there is a work-around.

- Phil
Title: Re: Output all dates in UTC?
Post by: geoffblack on November 17, 2017, 04:20:40 PM
I've run into another oddity in processing with timezone data. I have a JPG containing the following raw XMP data:
xmp:ModifyDate="2014-05-12T15:16:33-04:00"

Wtih the environment TZ set to UTC, and using the default date format output, ExifTool outputs this XML:
<XMP-xmp:ModifyDate>2014:05:12 15:16:33-04:00</XMP-xmp:ModifyDate>

It seems like ExifTool is parsing the date, since it's outputting the date portion with colons, but it isn't converting the date to UTC like it does correctly with the EXE:TimeStamp field I mentioned earlier.
Title: Re: Output all dates in UTC?
Post by: Phil Harvey on November 17, 2017, 11:03:37 PM
Right.  String-based date/time values are not converted because they carry their own timezone information.  The timezone setting affects only numerical epoch-based times because a time zone must be assumed to convert these to a string.

- Phil
Title: Re: Output all dates in UTC?
Post by: geoffblack on November 27, 2017, 04:18:35 PM
I understand the rationale behind leaving those alone, but if you're already parsing them, and there's a timezone set via API or environment var, wouldn't it make sense to convert all output to the same timezone?
Title: Re: Output all dates in UTC?
Post by: Phil Harvey on November 27, 2017, 09:34:56 PM
No.  The time zone is information that could be significant.  Also, I seem to recall that either the XMP or MWG specification recommends showing the original time zone.  So if the time zone is stored in the file, ExifTool shows it.

- Phil
Title: Re: Output all dates in UTC?
Post by: geoffblack on November 28, 2017, 10:36:36 AM
Understood. Appreciate you taking the time to discuss.
Title: Re: Output all dates in UTC?
Post by: geoffblack on November 28, 2017, 03:11:57 PM
One final question on timezone output: If you have a date without timezone information, like the IFD0:ModifyDate, and set a date format like "%Y-%m-%d %H:%M:%S%z" with the TZ env var set to "UTC", ExifTool will always add "+0000".

Example raw data: "2014:05:12 15:16:33"; ExifTool XML output:
<IFD0:ModifyDate>2014-05-12 15:16:33+0000</IFD0:ModifyDate>

Using the default date format, ExifTool outputs the datetime without a timezone:
<IFD0:ModifyDate>2014:05:12 15:16:33</IFD0:ModifyDate>.

I understand the reasoning for this, but is the default date format the only way to get timezone-naive output on dates that don't have timezone information?
Title: Re: Output all dates in UTC?
Post by: Phil Harvey on November 28, 2017, 04:14:09 PM
I don't think I understand the question.  Note that there are 3 different types of date/time values.  You are talking about number 2 with IFD0:ModifyDate:

1. A date/time complete with time zone (eg. most XMP date/times)

--> ExifTool shows the complete date/time with time zone

2. A relative date/time with no time zone (eg. EXIF date/time tags)

--> ExifTool shows the date/time without a time zone

3. An absolute date/time with no time zone (eg. System date/time tags, or some QuickTime date/time tags when QuickTimeUTC is set)

--> ExifTool shows the date/time in the local system time zone

- Phil
Title: Re: Output all dates in UTC?
Post by: geoffblack on November 28, 2017, 04:23:02 PM
Right, so in the case of #2, if I set a date format string that includes "%z", ExifTool will output "+0000" at the end of that datetime (with environment var TZ set to "UTC") even though there is no timezone information. I'm asking if that is a bug or as intended.
Title: Re: Output all dates in UTC?
Post by: Hayo Baan on November 29, 2017, 02:09:26 AM
Looks like intentional to me; you ask for the timezone with the %z specification :)
Title: Re: Output all dates in UTC?
Post by: Phil Harvey on November 29, 2017, 07:20:30 AM
Yup.
Title: Re: Output all dates in UTC?
Post by: geoffblack on November 29, 2017, 10:44:40 AM
Quote from: Hayo Baan on November 29, 2017, 02:09:26 AM
Looks like intentional to me; you ask for the timezone with the %z specification :)

Ha! Yes, yes. Shame strftime doesn't have a conditional %z.
Title: Re: Output all dates in UTC?
Post by: Phil Harvey on November 29, 2017, 11:09:20 AM
You could try something like this maybe to filter the default date/time formats:

exiftool -api filter="s/^(\d{4}):(\d{2}):(\d{2}) /$1-$2-$3 /" ...

- Phil
Title: Re: Output all dates in UTC?
Post by: geoffblack on November 29, 2017, 11:26:24 AM
Quote from: Phil Harvey on November 29, 2017, 11:09:20 AM
You could try something like this maybe to filter the default date/time formats:
exiftool -api filter="s/^(\d{4}):(\d{2}):(\d{2}) /$1-$2-$3 /" ...

Yeah, I'll take care of it in post-processing. It's actually nice to be able to maintain the timezone naivety, so I'll deal with the default format. Thanks, again.