OffsetTime

Started by wywh, November 02, 2023, 03:52:20 AM

Previous topic - Next topic

wywh

I recently enabled timezone display in macOS Sonoma Photos.app with (this was previously possible to change in the System Settings GUI):

defaults write NSGlobalDomain AppleICUTimeFormatStrings -dict-add "2" "HH:mm:ss z"

You can revert to the default with:

defaults delete NSGlobalDomain AppleICUTimeFormatStrings

...and then noticed that a few dozen images showed incorrect timezone in Photos.app for images taken in the winter. They displayed +03:00 instead +02:00 which was incorrect because DST had ended 30.10.2022.

I checked the time tags, and sure enough, OffsetTimeOriginal was somehow incorrectly set at +03:00:

exiftool -a -G1 -s -Time:All image.jpg
[ExifIFD]       DateTimeOriginal                : 2022:12:24 14:16:42
[ExifIFD]       OffsetTime                      : +02:00
[ExifIFD]       OffsetTimeOriginal              : +03:00
[ExifIFD]       OffsetTimeDigitized             : +03:00

I tested and verified that Photos.app gets the timezone from OffsetTimeOriginal and ignores other OffsetTime* tags. I also verified that such incorrect timezone affects sorting. BTW if there is no OffsetTimeOriginal, then GPS location affects sorting. (iOS 15.5 or later do not have GPSTimeStamp anymore, only GPSDateStamp, and it is moved to OffsetTime* tags).

I don't know what workflow might have caused that error. All such images were originally Canon .cr3 images edited with the latest Lightroom to .jpg. I must check the camera settings.

Anyway, I used GraphicConverter 12.0.7 to correct the timezone via Modify Exif Date > Set Exif Date Time Zone...

I guess I could have made an exiftool command that checked such incorrect or different OffsetTime* tags (after checking what DST was in effect then) and fixed it? But I did it manually to prevent dumb mistakes although it took almost an hour to go through 1800 images (I used exiftool to filter OffsetTime* as a list so I could spot errors).

p.s. After fixing the timezones I used Carbon Copy Cloner to backup the images. But later I had a hunch that the backup went too fast. And sure, enough, CCC did not backup the updated images. Why? Well, CCC looks for changed file size and file modification date when deciding if the file has changed. Just changing such +03:00 to +02:00 does not change file size one bit, and I have usually set GC and exiftool to preserve file dates even after editing metadata. CCC has an option to use md5 checksum which fixes this issue but it is quite slow so I do not use that. Instead, I now did a small change to the enclosing folder name so CCC backupped ALL its contents. ...it is a FAQ in Photos forums why file dates change and are "wrong" but I guess this is one good reason for that!

- Matti

StarGeek

Quote from: wywh on November 02, 2023, 03:52:20 AMI don't know what workflow might have caused that error. All such images were originally Canon .cr3 images edited with the latest Lightroom to .jpg. I must check the camera settings.

I know nothing about newer Canons that would write a CR3, but in older Canons (and Nikons), there would be a a setting for Daylight time.  You would flip that on or off and that would adjust the time, so you wouldn't have to reset the clock twice a year.
"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

wywh

Quote from: wywh on November 02, 2023, 03:52:20 AMI guess I could have made an exiftool command that checked such incorrect or different OffsetTime* tags (after checking what DST was in effect then)

In movies '-api QuickTimeUTC=1' very handily checks when DST was in effect.

Is it possible to use that kind of feature to fix incorrect offset times in images?

Now I just made a list about the DST dates and manually fixed incorrect offsets. It was clumsy but with only 4 years worth of images manageable (I believe my older images do not have offset times but have not yet checked that).

- Matti

StarGeek

I did some digging through the exiftool code because I knew there were some subroutines that might be useful and came up with this.
${DATETAG#;DateFmt('%s');$_=TimeZoneString(GetTimeZone([localtime($_)],[gmtime($_)]))}

Example.  DateTimeOriginal is set for Jan 1st (Standard time) and CreateDate is set for July 1st (Daylight time). My computer is Pacific time, so -08:00/-07:00 would be the correct time zones.
C:\>exiftool -G -a -s -AllDates -OffsetTime* y:\!temp\Test4.jpg
[EXIF]          DateTimeOriginal                : 2023:01:01 12:00:00
[EXIF]          CreateDate                      : 2023:07:01 12:00:00

C:\>exiftool -P -overwrite_original "-OffsetTimeOriginal<${DateTimeOriginal#;DateFmt('%s');$_=TimeZoneString(GetTimeZone([localtime($_)],[gmtime($_)]))}" "-OffsetTimeDigitized<${CreateDate#;DateFmt('%s');$_=TimeZoneString(GetTimeZone([localtime($_)],[gmtime($_)]))}" y:\!temp\Test4.jpg
    1 image files updated

C:\>exiftool -G -a -s -AllDates -OffsetTime* y:\!temp\Test4.jpg
[EXIF]          DateTimeOriginal                : 2023:01:01 12:00:00
[EXIF]          CreateDate                      : 2023:07:01 12:00:00
[EXIF]          OffsetTimeOriginal              : -08:00
[EXIF]          OffsetTimeDigitized             : -07:00

There might be better routines in the exiftool code, but this is what I came up with.
"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

wywh

Quote from: StarGeek on November 05, 2023, 12:26:08 PMsome subroutines that might be useful

Thanks for the tip, but in at least macOS 14 that does not readily work (exiftool 12.60):

exiftool -a -G1 -s -AllDates '-OffsetTime*' 2022-1224-1416-42.jpg
[ExifIFD]       DateTimeOriginal                : 2022:12:24 14:16:42
[ExifIFD]       CreateDate                      : 2022:12:24 14:16:42
[IFD0]          ModifyDate                      : 2022:12:24 14:16:42
[ExifIFD]       OffsetTime                      : +02:00
[ExifIFD]       OffsetTimeOriginal              : +03:00
[ExifIFD]       OffsetTimeDigitized             : +03:00

exiftool -P -overwrite_original '-OffsetTimeOriginal<${DateTimeOriginal#;DateFmt('%s');$_=TimeZoneString(GetTimeZone([localtime($_)],[gmtime($_)]))}' 2022-1224-1416-42.jpg
Warning: Global symbol "%s" requires explicit package name (did you forget to declare "my %s"?) for 'DateTimeOriginal' - 2022-1224-1416-42.jpg
Warning: No writable tags set from 2022-1224-1416-42.jpg
    0 image files updated
    1 image files unchanged

- Matti

StarGeek

On Mac/Linux, you need to swap quotes.  The double quotes in the command I posted become single quotes and the single quotes become double quotes.

The error is because you didn't swap the quotes around the %s.

Optionally, you can drop DateFmt("%s") and use the -d (-dateFormat) option. For example, -d %s, but in doing this, you need to remove the hashtags after the tag names.

I opted for including the date format change inline so you can use the -d option for other tags if needed.
"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

wywh

Quote from: StarGeek on November 05, 2023, 05:37:21 PMdidn't swap the quotes around the %s

Doh! Thanks for pointing that out. I was too eager to replace ALL quotes to single, and the error message confused me. So this works perfectly with DST OFF/ON:

exiftool -a -G1 -s -AllDates '-OffsetTime*' 2022-1224-1416-42.jpg
[ExifIFD]       DateTimeOriginal                : 2022:12:24 14:16:42
[ExifIFD]       CreateDate                      : 2022:12:24 14:16:42
[IFD0]          ModifyDate                      : 2022:12:24 14:16:42
[ExifIFD]       OffsetTime                      : +02:00
[ExifIFD]       OffsetTimeOriginal              : +03:00
[ExifIFD]       OffsetTimeDigitized             : +03:00
exiftool -P -overwrite_original '-OffsetTime<${DateTimeOriginal#;DateFmt("%s");$_=TimeZoneString(GetTimeZone([localtime($_)],[gmtime($_)]))}' '-OffsetTimeOriginal<${DateTimeOriginal#;DateFmt("%s");$_=TimeZoneString(GetTimeZone([localtime($_)],[gmtime($_)]))}' '-OffsetTimeDigitized<${DateTimeOriginal#;DateFmt("%s");$_=TimeZoneString(GetTimeZone([localtime($_)],[gmtime($_)]))}' 2022-1224-1416-42.jpg
    1 image files updated
exiftool -a -G1 -s -AllDates '-OffsetTime*' 2022-1224-1416-42.jpg
[ExifIFD]       DateTimeOriginal                : 2022:12:24 14:16:42
[ExifIFD]       CreateDate                      : 2022:12:24 14:16:42
[IFD0]          ModifyDate                      : 2022:12:24 14:16:42
[ExifIFD]       OffsetTime                      : +02:00
[ExifIFD]       OffsetTimeOriginal              : +02:00
[ExifIFD]       OffsetTimeDigitized             : +02:00

exiftool -a -G1 -s -AllDates '-OffsetTime*' 2023-0601-1200-00.jpg
[ExifIFD]       DateTimeOriginal                : 2023:06:01 12:00:00
[ExifIFD]       CreateDate                      : 2023:06:01 12:00:00
[IFD0]          ModifyDate                      : 2023:06:01 12:00:00
[ExifIFD]       OffsetTime                      : +02:00
[ExifIFD]       OffsetTimeOriginal              : +02:00
[ExifIFD]       OffsetTimeDigitized             : +02:00
exiftool -P -overwrite_original '-OffsetTime<${DateTimeOriginal#;DateFmt("%s");$_=TimeZoneString(GetTimeZone([localtime($_)],[gmtime($_)]))}' '-OffsetTimeOriginal<${DateTimeOriginal#;DateFmt("%s");$_=TimeZoneString(GetTimeZone([localtime($_)],[gmtime($_)]))}' '-OffsetTimeDigitized<${DateTimeOriginal#;DateFmt("%s");$_=TimeZoneString(GetTimeZone([localtime($_)],[gmtime($_)]))}' 2023-0601-1200-00.jpg
    1 image files updated
exiftool -a -G1 -s -AllDates '-OffsetTime*' 2023-0601-1200-00.jpg
[ExifIFD]       DateTimeOriginal                : 2023:06:01 12:00:00
[ExifIFD]       CreateDate                      : 2023:06:01 12:00:00
[IFD0]          ModifyDate                      : 2023:06:01 12:00:00
[ExifIFD]       OffsetTime                      : +03:00
[ExifIFD]       OffsetTimeOriginal              : +03:00
[ExifIFD]       OffsetTimeDigitized             : +03:00

- Matti

StarGeek

I usually forget to double check if the command needs to be used on Mac/Linux.  I even have a short Perl script that grabs the clipboard, uses tr/// to swap the quotes, and place the results back on the clipboard.  I just forget to use it because its original purpose was for dealing with xpaths in CMD and that's what is stuck in my mind.
"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