Python APP - Add Timezone Offset

Started by sdb, August 04, 2022, 10:09:28 PM

Previous topic - Next topic


I expect few people (none?) will have any interest in the purpose of this app, but I thought I would post it anyway as I wanted the functionality and I found it an interesting exercise in developing a python app for iMatch.  Python was needed to access libraries not available in JavaScript.

The app operates on all files currently selected in iMatch, and modifies the Date Subject Created date by adding to it an appropriate timezone offset.  The time zone is determined by GPS coordinates associated with the file, or if no coordinates are available, a default time zone is assumed.

The command line options for the app are:

  -h, --help    show this help message and exit
  -deftz DEFTZ  Specify default timezone, (e.g. -deftz Europe/Oslo) for use when there are no GPS coords. If omitted, 'Europe/London' is default.
  -user USER    Specify user name alias if this has been set in iMatch Application settings. Otherwise not needed
  -createdate   Normally Date Subject Created is populated. By specifying this option, the same contents are also written to Create Date
  -v            Verbose output
  -np           Do not pause output for confirmations


You need 64 bit Python 3.8, 3.9 or 3.10. 

I recommend using a virtual environment (venv) for the python code.  After setting up the venv, from the command line: 
pip install -r requirements.txt

Then a Favourite can be created:
The Command to Execute should be: 

The Arguments should be
"<>" <options>

You can create multiple Favourites with different names/options , e.g. for different default time zones.


The date calculated by the app ignores any pre-existing timezone offset, and is based on (in order of priority): 
Exif DateTimeOriginal 
XMP DateTimeOriginal 
XMP:Photoshop Date Created (i.e. Date Subject Created) 

This app just changes the Date Subject Created field (and optionally Create Date) but as usual writeback propagates the change to other fields.

This app only makes sense in the context of storing, in Date Subject Created, the local date (relative to where the image was taken) with the timezone offset for that location.   This only works if "Metadata 2/XMP Import/Apply time-zone" is set to No when the images are imported.  Otherwise imported files will have their File.DateTime manipulated in dependence on the location of the computer running iMatch and whether Daylight Savings is in effect at the time of import.

PS The python code is but I had to zip this in order to upload.


Thanks for sharing  :)

I'm not sure about all the details you have coded in your custom app, but could this not be done with the Time Wiz app in IMatch?
Variables give you access to the GPS timestamps and offsets, if existing, and conditionals could pick the "best" timestamp for your specific device and metadata content.


Hi Mario.  You may be correct that TimeWiz could be used - I did try this first - but if so it is currently beyond my ability to work out a convenient workflow.

The reasons include:
- TimeWiz seems to want a literal for specifying a changed time zone, rather than a variable
- many of my images were restrospectively geotagged and have no GPS timestamps/offsets
- Although I often know where pictures were taken (even if not geotagged) I don't know the timezone offset so I would prefer this be automatically found (from GPS or by specifying the name of the timezone)
- I will often not be able to determine if Daylight Savings Time should be applied
- I don't know what you mean by "conditionals" - are these something you can automate?
- It seems that you would have to keep changing the TimeWiz settings to match different situations, which could be time-consuming and error-prone.

Actually I was going to post separately about this last point.  I have used the excellent TimeWiz quite a lot, and I think it would be further improved if you could name and save settings so they could be quickly retrieved.

PS My comments about the Metadata 2 setting may not be accurate - I don't seem to be able to edit my post.  I meant to say that the setting was needed if you want File.DateTime to match the local time when the image was taken - by far the best arrangement in my view.  But not strictly necessary for my app.


QuoteTimeWiz seems to want a literal for specifying a changed time zone, rather than a variable

When you use the set from variable option, you can also set the time-zone offset from any metadata tag that contains the correct information.

QuoteI don't know the timezone offset so I would prefer this be automatically found (from GPS or by specifying the name of the timezone)

The standard defines that EXIF metadata may/should include a time zone offset. This of course depends on the device used to record the image.
When there is an EXIF time-zone, IMatch detects and applies it. IMatch does not look for time-zone offsets in GPS records, QuickTime video track segments, proprietary maker notes or elsewhere.

When a small number of users have to deal with the problem that their device has not recorded time-zone offsets in EXIF but in GPS, or the GPS data has been added later somehow, setting the time-zone via the TimeWiz is usually quick and easy to do. Either by adding a fixed time-zone offset or by using a variable to fetch the offset (e.g. from GPS data) and apply it to the date created and date subject created tags.

I understand that there might be cases where not even the TimeWiz can help, but these should be very rare. And then your Python script comes in.