Handling Timezones in Python
summary
Claims that naive datetimes cause up to 26 hours of ambiguity and that duration arithmetic must run in UTC; demonstrates actual code recipes using Python 3.9+ zoneinfo (or the backport plus tzdata) and Django settings (USE_TZ, timezone.activate, make_aware). Shows surprising pytz failure (example producing a UTC offset of 4h56m), gives concrete fixes: construct timezone-aware datetimes, store and compute in UTC, do calendar math on dates, convert to user timezone for display — code and slides provided.
AI-written summary · about
chapters (16)
- 0:00Start
- 0:44Motivation
- 2:59Outline
- 3:56Don't use naive datetimes
- 6:51Don't use dates without a timezone
- 8:35Don't do duration arithmetic outside of UTC
- 16:59Maximum compatibility
- 17:59Get current time
- 18:54Convert datetime to a date in a timezone
- 21:13Duration math on UTC datetimes
- 21:42Calendar math on dates
- 22:55Django timezone setup
- 23:38Templates automatically convert to localtime
- 24:25Converting to localtime
- 24:40Attaching a timezone to a naive datetime
- 25:14Summary
related talks
30mWorking with Time Zones: Everything You Wish You Didn't Need to Know
28mTime Zones in Python: Everything You Wish You Didn't Need
41mimport time_travel: A Primer on Timezones in Python
18mManaging Time like a Time Lord: It's bigger on the inside
27mThe time paradox: Building Timezone-safe python/django applications.
45mEverything You Never Wanted to Know About Time Zones
38mA Matter of Time
09mA Day Has Only 24±1 Hours
