Repository navigation
fix: make get_datetaken timezone-aware when exif provides an offset - #28
Merged
Merged
Conversation
This was referenced Sep 12, 2026
Coverage Report for CI Build 34898527593Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage increased (+0.2%) to 98.454%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Owner
Author
|
Review finding addressed in |
get_datetaken returned a naive datetime even when the exif data carried an UTC offset or GPS time, which triggers Django's naive datetime warning and stores the wrong instant with USE_TZ=True. Use OffsetTimeOriginal / OffsetTime for DateTimeOriginal, treat GPSDateTime as UTC, and keep the naive fallback only for files without any offset information. Refs #17
A present but malformed offset was silently ignored, returning a naive datetime even though the file claims to carry timezone information. Mirrors the existing invalid-datetime behavior; a valid GPSDateTime is still preferred when it is available.
escaped
force-pushed
the
fix/datetaken-timezone
branch
from
September 14, 2026 21:23
48cb745 to
ced103d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Fix #17. With
USE_TZ = True,get_datetakenreturned naive datetimes evenwhen the exif data contained
OffsetTimeOriginal/OffsetTimeor aGPSDateTime, so Django warned about a naive datetime and stored the value inthe default timezone — the wrong instant for photos taken elsewhere.
Walkthrough
DateTimeOriginalis combined withOffsetTimeOriginal(or theOffsetTimefallback) and returned with that UTC offset.GPSDateTimeis treated as UTC, including the...Zvalues ExifToolactually emits (the old code failed to parse those and ignored the tag).
DateTimeOriginalhas no offset, an awareGPSDateTimeis preferredover a naive original; a valid GPS value is also used when the offset is
unparseable.
ExifErrorinstead of silently returning anaive datetime (review finding).
the README explains how to handle that with
make_aware().Changes
exiffield/getters.pyget_datetaken+ parse helpertests/test_getters.pyREADME.mdmake_aware()recipeCHANGELOG.md[Unreleased]Testing
Red first: 5 of the new/updated cases failed against the old implementation
(
AssertionError, plusExifErrorfor the...ZGPS value); themalformed-offset case failed against the first revision of the fix. After:
%zparsing of theZsuffix was also checked on Python 3.10, the minimumsupported version.
CI on
48cb745: run 34694505570 — 14/14 jobs success.PR breakdown
Stacked on the modernization branch
test/e2e(PR #26). Merge in order.get_datetaken