osxphotos: Clarification ask: timewarp with --timezone 'named timezone' and --match-time: seems --match-time is ignored when using a 'named timezone'
Before submitting a bug report, please ensure you are running the most recent version of osxphotos and that the bug is reproducible on the latest version
$ osxphotos --version
osxphotos, version 0.69.2
Python 3.12.7 (main, Oct 11 2024, 17:54:25) [Clang 14.0.0 (clang-1400.0.29.202)]
Python executable: /Users/XXX/Documents/GitHub/osxphotos/venv/bin/python
macOS 12.7.6, x86_64
Describe the bug
Possibly not a bug, maybe an enhancement or I’misreading the timewarp scenarios with --timezone ‘named timezone’ vs UTCOffset and --match-time: for me it seems --match-time option is ignored when using a ‘named timezone’.
- Side Comment: it also seems “–inspect” reports the timestamp shifted and UTC Offset incorrectly and not accounting for DST in test 1. and 3. It should show +02:00 and not +01:00 for UTC Offset.
From help timewarp --timezone we have this note also:
Note: when a named timezone is provided, daylight savings time will be considered when adjusting the time; it will not be considered when a UTC offset is provided. For list of valid IANA timezone names, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
| Test | initial date_time on Photos | initial --inspect | –timezone | –match-time | final --inspect | final date_time on Photos | Comment |
|---|---|---|---|---|---|---|---|
| 1 | 2017-06-24 21:26:51 GMT+1 | 2017-06-24 21:26:51+0100, +0100, Europe/Lisbon | ‘Europe/Madrid’ | True | 2017-06-24 21:26:51+0100, +0100, Europe/Madrid | 2017-06-24 22:26:51 CEST | Preferred to have CEST but timestamp is shifted |
| 2 | 2017-06-24 21:26:51 GMT+1 | 2017-06-24 21:26:51+0100, +0100, Europe/Lisbon | UTC Offset +02:00 | True | 2017-06-24 21:26:51+0200, +0200, GMT+0200 | 2017-06-24 21:26:51 GMT+2 | Correct timestamp and timezone. Would like it to be CST |
| 3 | 2017-06-24 21:26:51 GMT+1 | 2017-06-24 21:26:51+0100, +0100, Europe/Lisbon | ‘Europe/Madrid’ | False | 2017-06-24 21:26:51+0100, +0100, Europe/Madrid | 2017-06-24 22:26:51 CEST | Same as case 1. Preferred to have CEST but timestamp is shifted |
To Reproduce
1. Using ‘named timezone’ --match-time
Test 1 detail
$ osxphotos timewarp -i
filename, uuid, photo time (local), photo time, timezone offset, timezone name, date added (local)
IMG_20170624_212651.JPG, 8984A3C1-EFD5-4AB2-9DB4-B39D32C48E3D, 2017-06-24 21:26:51+0100, 2017-06-24 21:26:51+0100, +0100, Europe/Lisbon, 2017-09-02 22:27:16+0100
$ osxphotos timewarp --timezone 'Europe/Madrid' --verbose --timestamp --match-time --force
2025-01-08 13:16:15.728033 -- Skipping date/time update for photo IMG_20170624_212651.JPG (8984A3C1-EFD5-4AB2-9DB4-B39D32C48E3D), already matches new timezone Europe/Madrid
2025-01-08 13:16:15.783004 -- Updated timezone for photo IMG_20170624_212651.JPG (8984A3C1-EFD5-4AB2-9DB4-B39D32C48E3D) from Europe/Lisbon, offset=3600 to Europe/Madrid, offset=3600
2025-01-08 13:16:15.784026 -- Done.
$ osxphotos timewarp -i
filename, uuid, photo time (local), photo time, timezone offset, timezone name, date added (local)
IMG_20170624_212651.JPG, 8984A3C1-EFD5-4AB2-9DB4-B39D32C48E3D, 2017-06-24 21:26:51+0100, 2017-06-24 21:26:51+0100, +0100, Europe/Madrid, 2017-09-02 22:27:16+0100
In Photos in the Photo Info (enabling display of timezone on the Mac Regional Settings): 2017-06-24 22:26:51 CEST
2. Using ‘UTC Offset’ --match-time
Test 2 detail
$ osxphotos timewarp -i
filename, uuid, photo time (local), photo time, timezone offset, timezone name, date added (local)
IMG_20170624_212651.JPG, 8984A3C1-EFD5-4AB2-9DB4-B39D32C48E3D, 2017-06-24 21:26:51+0100, 2017-06-24 21:26:51+0100, +0100, Europe/Lisbon, 2017-09-02 22:27:16+0100
$ osxphotos timewarp --timezone '+02:00' --verbose --timestamp --match-time --force
2025-01-08 13:34:17.978847 -- Adjusted local date/time for photo IMG_20170624_212651.JPG (8984A3C1-EFD5-4AB2-9DB4-B39D32C48E3D) to 2017-06-24 20:26:51 to match previous time 2017-06-24 21:26:51 but in new timezone GMT+0200.
2025-01-08 13:34:17.982241 -- Photo date/time is now 2017-06-24 20:26:51 in new timezone GMT+0200.
2025-01-08 13:34:18.043436 -- Updated timezone for photo IMG_20170624_212651.JPG (8984A3C1-EFD5-4AB2-9DB4-B39D32C48E3D) from Europe/Lisbon, offset=3600 to GMT+0200, offset=7200
2025-01-08 13:34:18.044173 -- Done.
$ NOk.2017 [1102]> osxphotos timewarp -i
filename, uuid, photo time (local), photo time, timezone offset, timezone name, date added (local)
IMG_20170624_212651.JPG, 8984A3C1-EFD5-4AB2-9DB4-B39D32C48E3D, 2017-06-24 20:26:51+0100, 2017-06-24 21:26:51+0200, +0200, GMT+0200, 2017-09-02 22:27:16+0100
In Photos in the Photo Info (enabling display of timezone on the Mac Regional Settings): 2017-06-24 21:26:51 GMT+2
3. Using ‘named timezone’
Test 3 detail
$ osxphotos timewarp -i
filename, uuid, photo time (local), photo time, timezone offset, timezone name, date added (local)
IMG_20170624_212651.JPG, 8984A3C1-EFD5-4AB2-9DB4-B39D32C48E3D, 2017-06-24 21:26:51+0100, 2017-06-24 21:26:51+0100, +0100, Europe/Lisbon, 2017-09-02 22:27:16+0100
$ osxphotos timewarp --timezone 'Europe/Madrid' --verbose --timestamp --force
2025-01-08 13:40:48.517488 -- Updated timezone for photo IMG_20170624_212651.JPG (8984A3C1-EFD5-4AB2-9DB4-B39D32C48E3D) from Europe/Lisbon, offset=3600 to Europe/Madrid, offset=3600
2025-01-08 13:40:48.518577 -- Done.
$ osxphotos timewarp -i
filename, uuid, photo time (local), photo time, timezone offset, timezone name, date added (local)
IMG_20170624_212651.JPG, 8984A3C1-EFD5-4AB2-9DB4-B39D32C48E3D, 2017-06-24 21:26:51+0100, 2017-06-24 21:26:51+0100, +0100, Europe/Madrid, 2017-09-02 22:27:16+0100
In Photos in the Photo Info (enabling display of timezone on the Mac Regional Settings): 2017-06-24 22:26:51 CEST
Expected behavior Would like to use --timezone ‘named timezone’ (respecting DST) and being able to use --match-time to keep the same timestamp.
Screenshots N/A
Desktop (please complete the following information):
$ sw_vers
ProductName: macOS
ProductVersion: 12.7.6
BuildVersion: 21H1320
Additional context Add any other context about the problem here.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 34 (34 by maintainers)
Commits related to this issue
- Clarification ask: timewarp with --timezone 'named timezone' and --match-time: seems --match-time is ignored when using a 'named timezone' #1777 possibly to rollback. — committed to oPromessa/osxphotos by oPromessa 2 years ago
- Revert "Clarification ask: timewarp with --timezone 'named timezone' and --match-time: seems --match-time is ignored when using a 'named timezone' #1777 possibly to rollback." This reverts commit e... — committed to oPromessa/osxphotos by oPromessa 2 years ago
- Clarification ask: timewarp with --timezone 'named timezone' and --match-time: seems --match-time is ignored when using a 'named timezone' Fixes #1777 — committed to oPromessa/osxphotos by oPromessa 2 years ago
- Added tests for #1777 — committed to RhetTbull/osxphotos by RhetTbull 2 years ago
- Added tests for #1777 (#1841) — committed to RhetTbull/osxphotos by RhetTbull 2 years ago
- Fix for #1777 for real this time — committed to RhetTbull/osxphotos by RhetTbull 2 years ago
- Fix for #1777 for real this time (#1843) — committed to RhetTbull/osxphotos by RhetTbull 2 years ago
This is awesome. Ran the tests on WEST timezone:
OK, I think I have this finally fixed. This will also fix daylight savings adjustments so they work correctly (see example below). I need to add a couple more test cases then will try to merge and release this week.
If in Europe/Madrid on 2024-03-031, Setting a time delta of 1 hour from 2024-03-31 01:00:00+01:00 now correctly sets the time ahead 2 hours and changes the timezone 2024-03-31 03:00:00+02:00, account for daylight savings time.
I’m getting close I think. I’ve updated all the parts of date/time manipulation in timewarp to use whenever which is a python datetime library that accounts for DST. There’s a bug in the
--match-timelogic when crossing DST boundaries I need to track down then this should be fixed along with #1839. Have I mentioned that I hate working with timezones and DST?@oPromessa I’ve confirmed this is a bug. Thanks again for the detailed debugging details.
I set my Mac timezone to CET and get the same results you are.
The following script runs the timezone commands in sequence so I can test this:
I’ll do some more digging to figure out where the problem is. As you pointed out it’s likely in
update_photo_time_for_new_timezone.I’m getting close to being able to tackle this. I’ve gotten the new timewarp code working (but still one new issue #1839) and working now to get
osxphotos importto use the new code from timewarp (which accounts for timezone when parsing a date from the filename with--parse-date). Once that is done, I think I can tackle this. (I think it’s been fixed but have not created a test yet).I have 1 failing test left before I can push these changes!
Getting close…
@oPromessa this is because the
PhotoTimeZoneUpdateris used inosxphotos timewarpto batch update a batch of photos with a given timezone.I have made significant changes to all the timezone code in another working branch and and working through a couple failing tests to get this released. Unfortunately I’ve only got a couple hours a week lately to work on osxphotos so it’s going slowly. As soon as I get that branch merged we can verify that it fixes this issue and if not, implement you changes. Until then any changes to any of the timezone code will cause merge conflicts.
Hi @oPromessa I think this is fixed in another branch I’m working. Just need to add a test. I’ve been extremely busy so not able to get this branch merged. Will try to get to it soon.
@oPromessa I’m going to need to fix this for another branch I’m working on to fix import time / timezone (#849 and #1661) so I’ll update the fix for DST here as well.
I’ll take a look. Likely a bug. I completely rewrote this part of the code a few months ago and it was extremely tricky to get right. My least favorite topic in programming is working with timezones!