Calculate SonyDateTime-SonyDateTime2-> TimeZone string

Started by peho, July 11, 2023, 10:14:17 AM

Previous topic - Next topic

peho

I've really search for an answer, but can't find any that I can use with my basic Perl knowledge.

From my Sony a6000, I don't get any timezone meta data, but it saves UTC time to SonyDateTime and local time to SonyDateTime2 (and the other exif time tags).

For instance:
SonyDateTime: 2023:06:25 10:52:27
SonyDateTime2: 2023:06:25 17:52:27
For this example I would like to have the result -07:00 as a string that I could add to the other time values.

Ive started with something like this, but obviously it doesn't work...

"-UserComment<${SonyDateTime;$_=$self->GetValue('SonyDateTime')-$self->GetValue('SonyDateTime2')}"

"-UserComment<${SonyDateTime;s!^.{11}(.{2}).*!$1!}-${SonyDateTime2;s!^.{11}(.{2}).*!$1!}"

*edit: -d or dateFmt doesn't work in the exiftool implementation in the mobileapp I'm using.

StarGeek

#1
I had to go digging through the source code because I knew there was at least one subroutine to use.  Here's what I came up with.  I'm writing to the OffsetTimeOriginal as that would be the EXIF location for a time zone, but the result probably can be used to shift time in other tags.

exiftool "-OffsetTimeOriginal<"${SonyDateTime;$_=TimeZoneString((GetUnixTime($_)-GetUnixTime($self->GetValue('SonyDateTime2')))/60)}" /path/to/files/

Example using DateTimeOriginal and CreateDate with your values
C:\>exiftool -time:all --system:all -G1 -a -s y:\!temp\Test4.jpg
[ExifIFD]      DateTimeOriginal                : 2023:06:25 10:52:27
[ExifIFD]      CreateDate                      : 2023:06:25 17:52:27

C:\>exiftool -G1 -a -s "-OffsetTimeOriginal<${DateTimeOriginal;$_=TimeZoneString((GetUnixTime($_)-GetUnixTime($self->GetValue('CreateDate')))/60)}"  y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -time:all --system:all -G1 -a -s y:\!temp\Test4.jpg
[ExifIFD]      DateTimeOriginal                : 2023:06:25 10:52:27
[ExifIFD]      CreateDate                      : 2023:06:25 17:52:27
[ExifIFD]      OffsetTimeOriginal              : -07:00
[Composite]    SubSecDateTimeOriginal          : 2023:06:25 10:52:27-07:00

The command gets the Unix time of the current tag, which would be SonyDateTime in your example, then grabs the Unix time of your second tag (SonyDateTime2).  Because Unix time is seconds, you can then subtract one from the other, resulting in -25,200 seconds.  Divide by 60 to get minutes, as that is what TimeZoneString requires and the result is the difference between the time zones.

Since this is technically figuring out a time zone, no idea what would happen with adjustments greater than ±12:00.  But it wouldn't be hard to drop the TimeZoneString subroutine for manually figuring out the difference.  I believe that the Perl module Time::Piece is built into exiftool and there are a lot of options that can be found on StackExchage or PerlMonks.

Edit: Just adding this for when I refer back to this post. TimeZoneString will just reformat the number of minutes as ±HH:MM, which means it's flexible and could be used in other operations.  I tested it with ±1,980 minutes, which it correctly formatted as ±33: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

peho