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

Most upvoted comments

This is awesome. Ran the tests on WEST timezone:

$ osxphotos --version
osxphotos, version 0.71.0
Python 3.12.9 (main, Feb  4 2025, 14:38:38) [Clang 16.0.0 (clang-1600.0.26.6)]
Python executable: /Users/XXX/Documents/GitHub/osxphotos/venv/bin/python
macOS 15.5.0, x86_64
(venv) 

$ python -m pytest -v tests/test_cli_timewarp.py --timewarp
(...)
===== 59 passed in 130.43s (0:02:10) ======

$  python -m pytest   
(...)
==== 2430 passed, 249 skipped, 8 xfailed, 4 xpassed in 371.63s (0:06:11) ===

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.

$ osxphotos timewarp --force --verbose --date 2024-03-30 --time 23:00:00 --timezone "Europe/Madrid"

Updated date/time for photo IMG_6520.jpeg (53615D56-91F7-4908-81F1-B93B5DEA7449) from: 2017-12-24 21:26:51+01:00 to 2024-03-30 23:00:00+01:00

$ osxphotos timewarp --force --verbose --time-delta "+2 hours"

Updated date/time for photo IMG_6520.jpeg (53615D56-91F7-4908-81F1-B93B5DEA7449) from: 2024-03-30 23:00:00+01:00 to 2024-03-31 01:00:00+01:00

$ osxphotos timewarp --force --verbose --time-delta "+1 hour"

Updated date/time for photo IMG_6520.jpeg (53615D56-91F7-4908-81F1-B93B5DEA7449) from: 2024-03-31 01:00:00+01:00 to 2024-03-31 03:00:00+02:00

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-time logic 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.

UUID = 16BEC0BE-4188-44F1-A8F1-7250E978AD12

Initial state:
filename, uuid, photo time (local), photo time, timezone offset, timezone name, date added (local)
IMG_6551.mov, 16BEC0BE-4188-44F1-A8F1-7250E978AD12, 2021-10-05 05:00:00+0200, 2021-10-04 20:00:00-0700, -0700, GMT-0700, 2021-10-09 19:35:03+0200

Resetting date/time/timezone
Done.
filename, uuid, photo time (local), photo time, timezone offset, timezone name, date added (local)
IMG_6551.mov, 16BEC0BE-4188-44F1-A8F1-7250E978AD12, 2021-10-05 04:01:03+0200, 2021-10-04 19:01:03-0700, -0700, GMT-0700, 2021-10-09 19:35:03+0200

Video date delta -1 day
Done.
filename, uuid, photo time (local), photo time, timezone offset, timezone name, date added (local)
IMG_6551.mov, 16BEC0BE-4188-44F1-A8F1-7250E978AD12, 2021-10-04 04:01:03+0200, 2021-10-03 19:01:03-0700, -0700, GMT-0700, 2021-10-09 19:35:03+0200

Video time delta +1 hour
Done.
filename, uuid, photo time (local), photo time, timezone offset, timezone name, date added (local)
IMG_6551.mov, 16BEC0BE-4188-44F1-A8F1-7250E978AD12, 2021-10-04 05:01:03+0200, 2021-10-03 20:01:03-0700, -0700, GMT-0700, 2021-10-09 19:35:03+0200

Video date: 2021-10-04
Done.
filename, uuid, photo time (local), photo time, timezone offset, timezone name, date added (local)
IMG_6551.mov, 16BEC0BE-4188-44F1-A8F1-7250E978AD12, 2021-10-04 05:01:03+0200, 2021-10-03 20:01:03-0700, -0700, GMT-0700, 2021-10-09 19:35:03+0200

Video time: 20:00:00
Done.
filename, uuid, photo time (local), photo time, timezone offset, timezone name, date added (local)
IMG_6551.mov, 16BEC0BE-4188-44F1-A8F1-7250E978AD12, 2021-10-05 05:00:00+0200, 2021-10-04 20:00:00-0700, -0700, GMT-0700, 2021-10-09 19:35:03+0200

The following script runs the timezone commands in sequence so I can test this:

#!/bin/bash

OSXPHOTOS="python -m osxphotos"
UUID=$(OSXPHOTOS query --quiet --print '{uuid}' --name IMG_6551.mov)

echo "UUID = $UUID"
echo ""
echo "Initial state:"
$OSXPHOTOS timewarp --inspect --uuid $UUID

echo ""
echo "Resetting date/time/timezone"
$OSXPHOTOS timewarp --date "2021-10-04" --time "19:01:03" --timezone "-0700" --force --uuid $UUID
$OSXPHOTOS timewarp --inspect --uuid $UUID

echo ""
echo "Video date delta -1 day"
$OSXPHOTOS timewarp --date-delta "-1 day" --force --uuid $UUID
$OSXPHOTOS timewarp --inspect --uuid $UUID

echo ""
echo "Video time delta +1 hour"
$OSXPHOTOS timewarp --time-delta "+1 hour" --force --uuid $UUID
$OSXPHOTOS timewarp --inspect --uuid $UUID

echo ""
echo "Video date: 2021-10-04"
$OSXPHOTOS timewarp --date "2021-10-04" --force --uuid $UUID
$OSXPHOTOS timewarp --inspect --uuid $UUID

echo ""
echo "Video time: 20:00:00"
$OSXPHOTOS timewarp --time "20:00:00" --force --uuid $UUID
$OSXPHOTOS timewarp --inspect --uuid $UUID

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 import to 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!

FAILED tests/test_cli_timewarp.py::test_pull_exif_no_data_use_file_time - AssertionError: assert CompareValues(filename='IMG_6506.jpeg', uuid='7E9DF2EE-A5B0-4077-80EC-30565221A3B9', date_photos='2024-11-26 07:43:44', date_exif='', tz_offset_photos=...

Getting close…

It would maybe make sense to have it on the init function of class PhotoTimeZoneUpdater but the actual photo.date is not available at that time as photo is not an argument.

@oPromessa this is because the PhotoTimeZoneUpdater is used in osxphotos timewarp to 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!