Set SubSecCreateDate from GPSDateTime by using GeolocationTimeZone

Started by glup, April 24, 2025, 02:26:26 PM

Previous topic - Next topic

glup

I'm new to exiftool resp trying the first time to solve a complex edit of metadata. SubSecCreateDate shall represent local DateTime where the picture was taken. Something like

exiftool -if '$gpsmeasuremode# == 3' \
         -api geolocation '-SubSecCreateDate<${GPSDateTime;ShiftDate($GeolocationTimeZone#)} -TimeZone<$GeolocationTimeZone#' \
         myfile.ext

-if shall ensure that a valid GPS 3d-fix was made and that GPSDateTime and GPSLocation are complete and valid.

-api geolocation shall determinate from GPSLocation the Geolocation information, here GeolocationTimezone. This requires a newer version of exiftool than 12.76 in Ubuntu noble as I found out.

The problem seams to be that GeolocationTimezone contains the name of the TZ but not the offset as "+/-hh:mm". It seams to be not possible to get this by adding # at the end of the tagname as it works with GPSMeasureMode. But this seams not the complete problem since if I use $TimeZone as the Parameter to ShiftTime it also does not work. As it is possible obvious I'm not familar with perl.  :-[

:-glup

StarGeek

Quote from: glup on April 24, 2025, 02:26:26 PMThe problem seams to be that GeolocationTimezone contains the name of the TZ but not the offset as "+/-hh:mm". It seams to be not possible to get this by adding # at the end of the tagname

Yes, because the database used contains the time zone name, not the offset.

Time zones are very messy to deal with (see Tome Scott's video, "The Problem with Time & Timezones"), and there really isn't an easy way ATM to figure out the correct offset.

It helps that you're on Linux, because the -api TimeZone option will accept time zone names, which Windows can't do. The problem is that you can't use the GeolocationTimeZone tag a parameter for this option.

The only workaround that I can think of is to first get a list of all the time zone names that you are going to be processing. Something like this. I'm not quite sure because I haven't used the geolocation option.
exiftool -api geolocation -p '$GeolocationTimeZone' /path/to/files/

Once you have the list, you could -api TimeZone option and the GPSDateTimeLocal config.

Copy the config file from that post and save it as a file in the same directory as exiftool. Or you could add it to your .ExifTool_config if you have one.

The command would be something like this. No idea if it will work, I'm making this up as I go and I can't test it because I'm on Windows

exiftool -config GPSDateTimeLocal.config  -api geolocation -d "'%Y:%m:%d %H:%M:%S%:z' -if '$GeolocationTimeZone eq "America/Los_Angeles" ' -api TimeZone='America/Los_Angeles' '-SubSecCreateDate<GPSDateTimeLocal' /path/to/files/

You would then replace the time zone name for each of the time zones in your list

The way this works it the -api TimeZone option temporarily sets the time zone for this command to the one you specify. This means the OS will figure out the correct time zone. The GPSDateTimeLocal then returns what the local time for that time zone would be. The -d (-dateFormat) option includes the %:z code, which is the time zone. Exiftool reads this value from the OS (see Note #2 under Common Date Format Codes).

The final result is the UTC time from GPSDateTime converted to the local zone as temporarily set by the -api TimeZone option.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

Upon further though, you could use the first command to create a script to run all the commands

exiftool -api geolocation -p 'exiftool -config GPSDateTimeLocal.config -api geolocation -d \'%Y:%m:%d %H:%M:%S%:z\' -if \'$$GeolocationTimeZone eq \"$GeolocationTimeZone\" -api TimeZone=\'$GeolocationTimeZone\' \'-SubSecCreateDate<GPSDateTimeLocal\' ' /path/to/files/ | uniq > script.txt

Ok, that's messy, and I'm not sure if I've properly escaped quotes. But it seems to output a command that looks correct
C:\>exiftool -api geolocation -p "exiftool -config GPSDateTimeLocal.config -api geolocation -d '%Y:%m:%d %H:%M:%S%:z' -if '$$GeolocationTimeZone eq \"$GeolocationTimeZone\" -api TimeZone='$GeolocationTimeZone' '-SubSecCreateDate<GPSDateTimeLocal'" y:\!temp\Test4.jpg
exiftool -config GPSDateTimeLocal.config -api geolocation -d '%Y:%m:%d %H:%M:%S%:z' -if '$GeolocationTimeZone eq "America/New_York" -api TimeZone='America/New_York' '-SubSecCreateDate<GPSDateTimeLocal'
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

And finally, this is what I use and why I haven't done anything with the Geolocate feature.

If you're willing to deal with Google's Time Zone API and get an API key, then the config file in this post will work by taking the DateTimeOriginal tag (local time for the location) and the GPS coordinates, and return the time zone (and other information) for those values.

It requires cURL, which isn't a problem for a Linux system.

The downside is that Google only gives you so many free hits. At the time I figured it was about 40,000 free hits, but I haven't checked to see if Google has changed this.

If you only have the GPSDateTime and not the local time, it would require some changes, though I'm not sure you can give Google a coordinate and UTC and get the local time data in return.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

glup

Quote from: StarGeek on April 24, 2025, 05:32:41 PMTime zones are very messy to deal with (see Tome Scott's video, "The Problem with Time & Timezones"), and there really isn't an easy way ATM to figure out the correct offset.

I'm aware of that, but the life depends on local time. And pictures are made in life and with this in local time. Local time ist needed to "understand" some pictures.
To calculate distances in time you possibly want to use JD, which is the number of days since 1. Januar −4712, 12:00 Uhr UT. You will not do this directly in local time if you are a kind of smart.

glup

Quote from: StarGeek on April 24, 2025, 05:32:41 PMThe only workaround that I can think of is to first get a list of all the time zone names that you are going to be processing. Something like this. I'm not quite sure because I haven't used the geolocation option.
exiftool -api geolocation -p '$GeolocationTimeZone' /path/to/files/

Once you have the list, you could -api TimeZone option and the GPSDateTimeLocal config.

Mmh, when I read the definition of GPSDateTimeLocal there is possibly a missunderstanding: I'm not interested in the TimeZone of my computer when I use exiftool. I need to use the TimeZone of the place the picture was made and based on this the local time of the creation of the picture.

But possibly I misunderstand the config file since I do not know what ConvertUnixTime(xxx,1) does. I was not able to find fast a documentation for this.

Also I do not understand -api TimeZone since I also do not find a documentation for this.

glup

Quote from: StarGeek on April 24, 2025, 05:54:35 PMIf you're willing to deal with Google's Time Zone API and get an API key, then the config file in this post will work by taking the DateTimeOriginal tag (local time for the location) and the GPS coordinates, and return the time zone (and other information) for those values.

Well, I'm not really willing to deal with any online service since the current information about timezones is on my notebook in /usr/share/zoneinfo/*. May be somehow "standard" on "Linux".

As I just read it may be possible to use somehow the result of ${TZ='$GeolocationTimezone' date --date='$GPSDateTime" -Ins}, but this is also somehow "Linux" specific as it uses the shell and not exiftool.

I just searched the net and found Perl TimeZone but as I said: I have no competence in Perl and don't know how to utilize that. But again: possible -api timezone is already a wrapper around that but without documentation I'm not able to find a elegant solution. It will be part of my automated workflow on importing my pictures, so it should be somehow reliable.

glup

Quote from: StarGeek on April 24, 2025, 05:45:08 PMC:\>exiftool -api geolocation -p "exiftool -config GPSDateTimeLocal.config -api geolocation -d '%Y:%m:%d %H:%M:%S%:z' -if '$$GeolocationTimeZone eq \"$GeolocationTimeZone\" -api TimeZone='$GeolocationTimeZone' '-SubSecCreateDate<GPSDateTimeLocal'" y:\!temp\Test4.jpg

I will try that when I'm back home. I have not one sample files with me  :( . Would it be possible to explain slightly the command? -if '$$GeolocationTimeZone eq \"$GeolocationTimeZone\" looks odd to me... The -d... is necessary so that '-SubSecCreateDate<GPSDateTime' works by using -api timezone, right? Isn't the fraction of seconds missing, so '%Y:%m:%d %H:%M:%S.%f%:z' should be correct just in case someone may need the ms?
Wouldn't be
exiftool -if '$gpsmeasuremode# == 3' -d '%Y:%m:%d %H:%M:%S.%f%:z'  \
         -api geolocation -api timezone='$GeoLocationTimezone' \
         '-SubSecCreateDate<GPSDateTime' myfile.ext
in just one command and without GPSDateTimeLocal.config sufficient? As I said before I do not know anything about -api timezone beside what you wrote here so I just adapted from what you wrote plus some wishful imagination that makes sense to me...

:-glup

StarGeek

Sorry about the walls of text, I probably wasn't as clear as I could have been.

Quote from: glup on April 25, 2025, 05:08:02 AMI'm not interested in the TimeZone of my computer when I use exiftool. I need to use the TimeZone of the place the picture was made and based on this the local time of the creation of the picture.

There's no misunderstanding. From my post
Quote from: StarGeek on April 24, 2025, 05:32:41 PMThe way this works it the -api TimeZone option temporarily sets the time zone for this command to the one you specify.

That means if you use -api TimeZone=America/New_York, the time zone for this command will temporarily be changed to EST/EDT, regardless of your current time zone.

QuoteAlso I do not understand -api TimeZone since I also do not find a documentation for this.

I linked to the documentation in my first post
Quote from: StarGeek on April 24, 2025, 05:32:41 PMIt helps that you're on Linux, because the -api TimeZone option will accept time zone names

The -api option is a way to access the Options functions of the exiftool library.

QuoteBut possibly I misunderstand the config file since I do not know what ConvertUnixTime(xxx,1) does. I was not able to find fast a documentation for this.

This is a subroutine that's part of the exiftool code. It is a simple way to handle Unix time to the format exiftool uses. It's not necessary to know anything about it. It's just a function called in the config file.

I would have shown you a working example if I could have, but I'm on Windows, and it doesn't know the Time Zone Names. But here's an example of how it works on Windows. Notice that the first listing is in my locale PST/PDT time zone, but I change it to EST/ETD with the -api Timezone option temporarily.
C:\>exiftool -G1 -a -s -File*Date y:\!temp\Test4.jpg
[System]        FileModifyDate                  : 2025:04:23 08:00:00-07:00
[System]        FileAccessDate                  : 2025:04:24 14:43:30-07:00
[System]        FileCreateDate                  : 1966:01:01 00:00:00-08:00

C:\>exiftool -G1 -a -s -api TimeZone=EST5EDT -File*Date y:\!temp\Test4.jpg
[System]        FileModifyDate                  : 2025:04:23 11:00:00-04:00
[System]        FileAccessDate                  : 2025:04:25 11:07:55-04:00
[System]        FileCreateDate                  : 1966:01:01 03:00:00-05:00
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

Quote from: glup on April 25, 2025, 05:42:15 AMAs I just read it may be possible to use somehow the result of ${TZ='$GeolocationTimezone' date --date='$GPSDateTime" -Ins}, but this is also somehow "Linux" specific as it uses the shell and not exiftool.

This is exactly what the -api Timezone does.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

Quote from: glup on April 25, 2025, 06:16:28 AMWould it be possible to explain slightly the command? -if '$$GeolocationTimeZone eq \"$GeolocationTimeZone\" looks odd to me...

I'm using exiftool to create an exiftool command. You would run the command I listed and redirect the output into a file. You would then set the execute permission on the file and run it as a script. I have limited knowledge of Linux, so I don't know the proper term, but in Windows terms, it would be running a command to create a BAT file, which would then be run to edit all the files.

I should have said that this is based upon the possibility that your files have multiple different time zones. If you already know the time zone, then you could just hard code it like the command I listed earlier (oops, noticed a mistake, fixing)
Quote from: StarGeek on April 24, 2025, 05:32:41 PMexiftool -config GPSDateTimeLocal.config  -api geolocation -d '%Y:%m:%d %H:%M:%S%:z' -if '$GeolocationTimeZone eq "America/Los_Angeles" ' -api TimeZone='America/Los_Angeles' '-SubSecCreateDate<GPSDateTimeLocal' /path/to/files/

QuoteThe -d... is necessary so that '-SubSecCreateDate<GPSDateTime' works by using -api timezone, right? Isn't the fraction of seconds missing, so '%Y:%m:%d %H:%M:%S.%f%:z' should be correct just in case someone may need the ms?

Ooops, sorry. You are correct to add the %f for subseconds.

QuoteWouldn't be
exiftool -if '$gpsmeasuremode# == 3' -d '%Y:%m:%d %H:%M:%S.%f%:z'  \
         -api geolocation -api timezone='$GeoLocationTimezone' \
         '-SubSecCreateDate<GPSDateTime' myfile.ext
in just one command and without GPSDateTimeLocal.config sufficient?

Unfortunately, no. As I said
Quote from: StarGeek on April 24, 2025, 05:32:41 PMThe problem is that you can't use the GeolocationTimeZone tag a parameter for this option.

The value needs to be set when the command is run, and the value of GeolocationTimeZone isn't know until the command is run and the file has been read.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype