Denny Biasiolli

The Time Paradox: Building Timezone-Safe Python/Django Applications

A financial reporting bug misclassified millions in revenue. The culprit? A simple query that failed to account for the difference between user and server timezones.

The Time Paradox: Building Timezone-Safe Python/Django Applications
#1about 4 minutes

A costly timezone bug in financial reporting

A real-world example shows how a simple query stored in UTC misclassified millions in revenue by ignoring the user's local timezone.

#2about 4 minutes

Defining timestamps, ISO 8601, and the Unix epoch

Timestamps are defined according to the ISO 8601 standard and commonly implemented as a Unix timestamp, which counts seconds since January 1st, 1970.

#3about 3 minutes

Why a timestamp is a moment, not a local time

A timestamp represents a single, unambiguous moment in time across the globe, while a timezone is merely a human-readable interpretation of that moment.

#4about 2 minutes

How daylight saving time can break scheduled tasks

A scheduled job sending daily statements at 9 AM suddenly started running an hour late due to differences in daylight saving time changes between the US and Europe.

#5about 4 minutes

Storing past events versus scheduling future events

For past events, always store timestamps in UTC, but for future events, store the user's intent by saving the local time and the timezone name.

#6about 3 minutes

Handling daylight saving time edge cases

Address the "phantom hour" during spring forward and the "duplicate hour" during fallback by knowing your library's behavior and asking the user for clarification.

#7about 4 minutes

Using timezone-aware datetimes in Python and JavaScript

Use Python's timezone-aware datetime objects to avoid ambiguity and leverage third-party libraries like Luxon in JavaScript to overcome the native Date object's limitations.

#8about 3 minutes

Configuring timezones in PostgreSQL and Django

Use PostgreSQL's `timestamp with time zone` type and enable Django's `USE_TZ` setting to automatically handle UTC storage and conversion to the active timezone.

#9about 4 minutes

Strategies for handling user-specific timezones in Django

Implement a middleware to activate a user's timezone based on their profile settings, a request header, or a cookie set by the browser.

#10about 1 minute

Final best practices for building timezone-safe applications

Always use timezone-aware datetimes, store events in UTC while displaying in local time, and explicitly ask users for the timezone during sensitive operations.

Related jobs
Jobs that call for the skills explored in this talk.

Featured Partners

Related Articles

View all articles

From learning to earning

Jobs that call for the skills explored in this talk.