The damned timezones

Started by sammyke007, September 28, 2024, 05:25:46 AM

Previous topic - Next topic

sammyke007

Hi

First: tnx for your great software!

Second:
I've started using exiftool to organize older phone *Screenshots* and *WA* (whatsapp) files. I have to this because of some changes in Immich that show incorrect time when a timezone is not specified...

I'm using the following commands to set the correct timezones because in Belgium (Europe/Brussels) we have CEST (GMT+2) en CET (GMT+2).

Is there an easier way to do this without looking for the exact date of CET>CEST and vice versa?

timezone_offset="+02:00"

for month in {04..09}; do
    /opt/ExifTool/exiftool '-alldates<${filename;$_=substr($_,0,19);tr/_/:/;}'$timezone_offset -OffsetTime=$timezone_offset -overwrite_original -progress -m 2022-$month-*WA*.@(jpg|mp4) 2022-$month-*Screenshot*.jpg
done

timezone_offset="+01:00"

for month in {01..03}; do
    /opt/ExifTool/exiftool '-alldates<${filename;$_=substr($_,0,19);tr/_/:/;}'$timezone_offset -OffsetTime=$timezone_offset -overwrite_original -progress -m 2022-$month-*WA*.@(jpg|mp4) 2022-$month-*Screenshot*.jpg
done

timezone_offset="+02:00"

for day in {27..31}; do
    /opt/ExifTool/exiftool '-alldates<${filename;$_=substr($_,0,19);tr/_/:/;}'$timezone_offset -OffsetTime=$timezone_offset -overwrite_original -progress -m 2022-03␅-$day*WA*.@(jpg|mp4) 2022-03-$day*Screenshot*.jpg
done

timezone_offset="+01:00"

for month in {11..12}; do
    /opt/ExifTool/exiftool '-alldates<${filename;$_=substr($_,0,19);tr/_/:/;}'$timezone_offset -OffsetTime=$timezone_offset -overwrite_original -progress -m 2021-$month-*WA*.@(jpg|mp4) 2021-$month-*Screenshot*.jpg
done

timezone_offset="+02:00"

for month in {04..10}; do
    /opt/ExifTool/exiftool '-alldates<${filename;$_=substr($_,0,19);tr/_/:/;}'$timezone_offset -OffsetTime=$timezone_offset -overwrite_original -progress -m 2021-$month-*WA*.@(jpg|mp4) 2021-$month-*Screenshot*.jpg
done

timezone_offset="+01:00"

for day in {31..31}; do
    /opt/ExifTool/exiftool '-alldates<${filename;$_=substr($_,0,19);tr/_/:/;}'$timezone_offset -OffsetTime=$timezone_offset -overwrite_original -progress -m 2021-10-$day*WA*.@(jpg|mp4) 2021-10-$day*Screenshot*.jpg
done

for month in {01..03}; do
    /opt/ExifTool/exiftool '-alldates<${filename;$_=substr($_,0,19);tr/_/:/;}'$timezone_offset -OffsetTime=$timezone_offset -overwrite_original -progress -m 2021-$month-*WA*.@(jpg|mp4) 2021-$month-*Screenshot*.jpg
done

timezone_offset="+02:00"

for day in {28..31}; do
    /opt/ExifTool/exiftool '-alldates<${filename;$_=substr($_,0,19);tr/_/:/;}'$timezone_offset -OffsetTime=$timezone_offset -overwrite_original -progress -m 2021-03-$day*WA*.@(jpg|mp4) 2021-03-$day*Screenshot*.jpg
done

timezone_offset="+01:00"

for month in {11..12}; do
    /opt/ExifTool/exiftool '-alldates<${filename;$_=substr($_,0,19);tr/_/:/;}'$timezone_offset -OffsetTime=$timezone_offset -overwrite_original -progress -m 2020-$month-*WA*.@(jpg|mp4) 2020-$month-*Screenshot*.jpg
done

timezone_offset="+02:00"

for month in {04..10}; do
    /opt/ExifTool/exiftool '-alldates<${filename;$_=substr($_,0,19);tr/_/:/;}'$timezone_offset -OffsetTime=$timezone_offset -overwrite_original -progress -m 2020-$month-*WA*.@(jpg|mp4) 2020-$month-*Screenshot*.jpg
done

and so on...


wywh

Quote from: sammyke007 on September 28, 2024, 05:25:46 AMIs there an easier way to do this without looking for the exact date of CET>CEST and vice versa?

It seems that on the Mac you can automatically copy the correct DST OFF/ON setting from the file date using TZ names like '-api TimeZone=America/New_York'. I guess this does not work on Windows where only manually setting it like "-api TimeZone=+04" works.

For example, DateTimeOriginal is initially correct but the file dates are not:

exiftool -a -G1 -s -e -api TimeZone=America/New_York -FileCreateDate -Time:All .
======== ./dst_on.jpg
[MacOS]         FileCreateDate                  : 2024:09:28 07:37:00-04:00
[System]        FileModifyDate                  : 2024:09:28 07:37:01-04:00
[IFD0]          ModifyDate                      : 2024:06:01 12:00:00
[ExifIFD]       DateTimeOriginal                : 2024:06:01 12:00:00
[ExifIFD]       CreateDate                      : 2024:06:01 12:00:00
======== ./dst_off.jpg
[MacOS]         FileCreateDate                  : 2024:09:28 07:37:01-04:00
[System]        FileModifyDate                  : 2024:09:28 07:37:01-04:00
[IFD0]          ModifyDate                      : 2024:01:01 12:00:00
[ExifIFD]       DateTimeOriginal                : 2024:01:01 12:00:00
[ExifIFD]       CreateDate                      : 2024:01:01 12:00:00

Copy DateTimeOriginal to file dates and then copy New York time zone and the correct DST winter/summer setting to OffsetTime:

exiftool '-FileModifyDate<DateTimeOriginal' '-FileCreateDate<DateTimeOriginal' -execute '-OffsetTime*<FileCreateDate' -common_args -P -overwrite_original -api TimeZone=America/New_York .
Result:

exiftool -a -G1 -s -e -api TimeZone=America/New_York -FileCreateDate -Time:All .
======== ./dst_on.jpg
[MacOS]         FileCreateDate                  : 2024:06:01 12:00:00-04:00
[System]        FileModifyDate                  : 2024:06:01 12:00:00-04:00
[IFD0]          ModifyDate                      : 2024:06:01 12:00:00
[ExifIFD]       DateTimeOriginal                : 2024:06:01 12:00:00
[ExifIFD]       CreateDate                      : 2024:06:01 12:00:00
[ExifIFD]       OffsetTime                      : -04:00
[ExifIFD]       OffsetTimeOriginal              : -04:00
[ExifIFD]       OffsetTimeDigitized             : -04:00
======== ./dst_off.jpg
[MacOS]         FileCreateDate                  : 2024:01:01 12:00:00-05:00
[System]        FileModifyDate                  : 2024:01:01 12:00:00-05:00
[IFD0]          ModifyDate                      : 2024:01:01 12:00:00
[ExifIFD]       DateTimeOriginal                : 2024:01:01 12:00:00
[ExifIFD]       CreateDate                      : 2024:01:01 12:00:00
[ExifIFD]       OffsetTime                      : -05:00
[ExifIFD]       OffsetTimeOriginal              : -05:00
[ExifIFD]       OffsetTimeDigitized             : -05:00

Or without -api TimeZone=America/New_York:

exiftool -a -G1 -s -e -FileCreateDate -Time:All .
======== ./dst_on.jpg
[MacOS]         FileCreateDate                  : 2024:06:01 19:00:00+03:00
[System]        FileModifyDate                  : 2024:06:01 19:00:00+03:00
[IFD0]          ModifyDate                      : 2024:06:01 12:00:00
[ExifIFD]       DateTimeOriginal                : 2024:06:01 12:00:00
[ExifIFD]       CreateDate                      : 2024:06:01 12:00:00
[ExifIFD]       OffsetTime                      : -04:00
[ExifIFD]       OffsetTimeOriginal              : -04:00
[ExifIFD]       OffsetTimeDigitized             : -04:00
======== ./dst_off.jpg
[MacOS]         FileCreateDate                  : 2024:01:01 19:00:00+02:00
[System]        FileModifyDate                  : 2024:01:01 19:00:00+02:00
[IFD0]          ModifyDate                      : 2024:01:01 12:00:00
[ExifIFD]       DateTimeOriginal                : 2024:01:01 12:00:00
[ExifIFD]       CreateDate                      : 2024:01:01 12:00:00
[ExifIFD]       OffsetTime                      : -05:00
[ExifIFD]       OffsetTimeOriginal              : -05:00
[ExifIFD]       OffsetTimeDigitized             : -05:00

- Matti

StarGeek

Assuming the computer is in the correct time zone, you could also do a two-step process and let the file system figure out the time zone for you.

exiftool '-FileModifyDate<${filename;$_=substr($_,0,19);tr/_/:/;}' -progress /path/to/files/
exiftool -overwrite_original -progress -m '-SubSecCreateDate<FileModifyDate' '-SubSecDateTimeOriginal<FileModifyDate' '-SubSecModifyDate<FileModifyDate' /path/to/files/

Though, I think more has to be done with getting the correct date/time from the filename, because I believe that WhatsApp files don't include time information in the filename.

The first command doesn't need -overwrite_original option because it is only editing the file system, not the file itself.

The second command is using the Composite tags that will set the main EXIF tags as well as the OffsetTime* tags at the same time.

Example. One filename is in January, standard time, and the other is July, Summer time
C:\>exiftool -time:all -G1 -a -s Y:\!temp\x\y
======== Y:/!temp/x/y/2024-01-01-12-00-00.jpg
[System]        FileModifyDate                  : 2024:09:10 06:54:21-07:00
[System]        FileAccessDate                  : 2024:09:28 07:23:33-07:00
[System]        FileCreateDate                  : 2024:09:09 08:42:26-07:00
======== Y:/!temp/x/y/2024-07-01-12-00-00.jpg
[System]        FileModifyDate                  : 2024:09:10 06:54:21-07:00
[System]        FileAccessDate                  : 2024:09:28 07:23:33-07:00
[System]        FileCreateDate                  : 2024:09:09 08:42:26-07:00
    1 directories scanned
    2 image files read

C:\>exiftool -P -overwrite_original "-FileModifyDate<Filename" Y:\!temp\x\y
    1 directories scanned
    2 image files updated

C:\>exiftool -time:all -G1 -a -s Y:\!temp\x\y
======== Y:/!temp/x/y/2024-01-01-12-00-00.jpg
[System]        FileModifyDate                  : 2024:01:01 12:00:00-08:00
[System]        FileAccessDate                  : 2024:01:01 12:00:00-08:00
[System]        FileCreateDate                  : 2024:09:09 08:42:26-07:00
======== Y:/!temp/x/y/2024-07-01-12-00-00.jpg
[System]        FileModifyDate                  : 2024:07:01 12:00:00-07:00
[System]        FileAccessDate                  : 2024:07:01 12:00:00-07:00
[System]        FileCreateDate                  : 2024:09:09 08:42:26-07:00
    1 directories scanned
    2 image files read

C:\>exiftool -P -overwrite_original "-SubSecCreateDate<FileModifyDate" "-SubSecDateTimeOriginal<FileModifyDate" "-SubSecModifyDate<FileModifyDate" Y:\!temp\x\y
    1 directories scanned
    2 image files updated

C:\>exiftool -time:all -G1 -a -s Y:\!temp\x\y
======== Y:/!temp/x/y/2024-01-01-12-00-00.jpg
[System]        FileModifyDate                  : 2024:01:01 12:00:00-08:00
[System]        FileAccessDate                  : 2024:09:28 07:25:01-07:00
[System]        FileCreateDate                  : 2024:09:09 08:42:26-07:00
[IFD0]          ModifyDate                      : 2024:01:01 12:00:00
[ExifIFD]       DateTimeOriginal                : 2024:01:01 12:00:00
[ExifIFD]       CreateDate                      : 2024:01:01 12:00:00
[ExifIFD]       OffsetTime                      : -08:00
[ExifIFD]       OffsetTimeOriginal              : -08:00
[ExifIFD]       OffsetTimeDigitized             : -08:00
[Composite]     SubSecCreateDate                : 2024:01:01 12:00:00-08:00
[Composite]     SubSecDateTimeOriginal          : 2024:01:01 12:00:00-08:00
[Composite]     SubSecModifyDate                : 2024:01:01 12:00:00-08:00
======== Y:/!temp/x/y/2024-07-01-12-00-00.jpg
[System]        FileModifyDate                  : 2024:07:01 12:00:00-07:00
[System]        FileAccessDate                  : 2024:09:28 07:25:01-07:00
[System]        FileCreateDate                  : 2024:09:09 08:42:26-07:00
[IFD0]          ModifyDate                      : 2024:07:01 12:00:00
[ExifIFD]       DateTimeOriginal                : 2024:07:01 12:00:00
[ExifIFD]       CreateDate                      : 2024:07:01 12:00:00
[ExifIFD]       OffsetTime                      : -07:00
[ExifIFD]       OffsetTimeOriginal              : -07:00
[ExifIFD]       OffsetTimeDigitized             : -07:00
[Composite]     SubSecCreateDate                : 2024:07:01 12:00:00-07:00
[Composite]     SubSecDateTimeOriginal          : 2024:07:01 12:00:00-07:00
[Composite]     SubSecModifyDate                : 2024:07:01 12:00:00-07:00
    1 directories scanned
    2 image files 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

sammyke007

Tnx for your quick support.
The computer is in the correct time zone (CEST or GMT+2) right now.

Whatsapp strips the EXIF data indeed, but I transfer my Whatsapp media to my NAS using Photosync on my Oneplus 9 Pro.
Photosync renames the files to "Recording time + file name" like you can see above. Recording time seems to be the time the image arrived on your phone. That works fine for me, except the timezones + Immich  :D.
So FileModifyDate is the important one to make the second command work?

StarGeek

Quote from: sammyke007 on September 28, 2024, 11:44:23 AMSo FileModifyDate is the important one to make the second command work?

Yes, because whatever operating system you're using already knows when Summer time starts and stops and will automatically apply the correct time zone.
"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

sammyke007

The two-step process is working excellent for my jpg images. 1000x thank you!
Any solution for mp4 files?
The composite tags don't seem to get written for mp4 files:

18:08:46|root@Docker.7: /opt/immich/photo/Oneplus 6 Sammy/All# exiftool -overwrite_original -progress -m '-SubSecCreateDate<FileModifyDate' '-SubSecDateTimeOriginal<FileModifyDate' '-SubSecModifyDate<FileModifyDate' 2018-12-21_18-17-49_VID-20181221-WA0005.mp4
======== 2018-12-21_18-17-49_VID-20181221-WA0005.mp4 [1/1]
Nothing changed in 2018-12-21_18-17-49_VID-20181221-WA0005.mp4
    0 image files updated
    1 image files unchanged
18:08:50|root@Docker.7: /opt/immich/photo/Oneplus 6 Sammy/All# exiftool -time:all -G0:1 -a -s 2018-12-21_18-17-49_VID-20181221-WA0005.mp4
[File:System]   FileModifyDate                  : 2018:12:21 18:17:49+01:00
[File:System]   FileAccessDate                  : 2024:09:29 18:08:50+02:00
[File:System]   FileInodeChangeDate             : 2024:09:29 18:08:45+02:00
[QuickTime]     CreateDate                      : 2018:12:21 17:17:49
[QuickTime]     ModifyDate                      : 2018:12:21 17:17:49
[QuickTime:Track1] TrackCreateDate              : 0000:00:00 00:00:00
[QuickTime:Track1] TrackModifyDate              : 0000:00:00 00:00:00
[QuickTime:Track1] MediaCreateDate              : 0000:00:00 00:00:00
[QuickTime:Track1] MediaModifyDate              : 0000:00:00 00:00:00
[QuickTime:Track2] TrackCreateDate              : 0000:00:00 00:00:00
[QuickTime:Track2] TrackModifyDate              : 0000:00:00 00:00:00
[QuickTime:Track2] MediaCreateDate              : 0000:00:00 00:00:00
[QuickTime:Track2] MediaModifyDate              : 0000:00:00 00:00:00
[QuickTime:UserData] DateTimeOriginal           : 2018:12:21 18:17:49+01:00
[XMP:XMP-exif]  DateTimeOriginal                : 2018:12:21 18:17:49
[XMP:XMP-xmp]   CreateDate                      : 2018:12:21 18:17:49
[XMP:XMP-xmp]   ModifyDate                      : 2018:12:21 18:17:49

StarGeek

Quote from: sammyke007 on September 29, 2024, 12:14:22 PMThe two-step process is working excellent for my jpg images. 1000x thank you!
Any solution for mp4 files?
The composite tags don't seem to get written for mp4 files:

The composite tags are set to only write EXIF tags, not XMP or Quicktime tags (see the Composite tags page).

AllDates would work for XMP tags in videos and the Quicktime:DateTimeOriginal, which is one of the video tags that is supposed to be local time and not UTC. It would also set the Quicktime CreateDate and ModifyDate tags.
C:\>exiftool -time:all --system:all -G1 -a -s Y:\!temp\Test1.mp4
[QuickTime]     CreateDate                      : 0000:00:00 00:00:00
[QuickTime]     ModifyDate                      : 0000:00:00 00:00:00
[Track1]        TrackCreateDate                 : 0000:00:00 00:00:00
[Track1]        TrackModifyDate                 : 0000:00:00 00:00:00
[Track1]        MediaCreateDate                 : 0000:00:00 00:00:00
[Track1]        MediaModifyDate                 : 0000:00:00 00:00:00
[Track2]        TrackCreateDate                 : 0000:00:00 00:00:00
[Track2]        TrackModifyDate                 : 0000:00:00 00:00:00
[Track2]        MediaCreateDate                 : 0000:00:00 00:00:00
[Track2]        MediaModifyDate                 : 0000:00:00 00:00:00

C:\>exiftool -P -overwrite_original -api QuickTimeUTC "-AllDates<FileModifyDate" Y:\!temp\Test1.mp4
    1 image files updated

C:\>exiftool -time:all --system:all -G1 -a -s Y:\!temp\Test1.mp4
[QuickTime]     CreateDate                      : 2024:06:06 19:00:00
[QuickTime]     ModifyDate                      : 2024:06:06 19:00:00
[Track1]        TrackCreateDate                 : 0000:00:00 00:00:00
[Track1]        TrackModifyDate                 : 0000:00:00 00:00:00
[Track1]        MediaCreateDate                 : 0000:00:00 00:00:00
[Track1]        MediaModifyDate                 : 0000:00:00 00:00:00
[Track2]        TrackCreateDate                 : 0000:00:00 00:00:00
[Track2]        TrackModifyDate                 : 0000:00:00 00:00:00
[Track2]        MediaCreateDate                 : 0000:00:00 00:00:00
[Track2]        MediaModifyDate                 : 0000:00:00 00:00:00
[UserData]      DateTimeOriginal                : 2024:06:06 12:00:00-07:00
[XMP-exif]      DateTimeOriginal                : 2024:06:06 12:00:00-07:00
[XMP-xmp]       CreateDate                      : 2024:06:06 12:00:00-07:00
[XMP-xmp]       ModifyDate                      : 2024:06:06 12:00:00-07: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

Another way to write multiple tags with the same value is to use the -UserParam option.

See this post.
"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

sammyke007

Just wanted to reply to say tnx! This helped a lot in +- 170.000 Immich assets with a lot of wrong or missing EXIF data!