Output all dates in UTC?

Started by geoffblack, November 15, 2017, 12:46:41 PM

Previous topic - Next topic

geoffblack

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!

Phil Harvey

A quick work-around is to set your system timezone to UTC.  I'll think about whether there is another way...

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

I'll add a new API TimeZone option in ExifTool 10.67, so this will work for future versions:

exiftool -api timezone=UTC ...

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

geoffblack

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.

Phil Harvey

Oops.  I may not be able to implement this in Windows if my hack didn't work.  :(

I'll look into this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Phil Harvey

OK.  In Windows, run this command before running ExifTool:

set TZ=UTC

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

geoffblack

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>

geoffblack

FYI confirmed that -api TimeZone=UTC in 10.67 does not work on Windows. Setting the environment variable TZ works great, though. Thanks, again.

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

geoffblack

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.

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

geoffblack

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?

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

geoffblack

Understood. Appreciate you taking the time to discuss.