โœ…

Developer Checklists

Pre-deployment checklists and code review guidelines for time handling. Use these to catch time-related bugs before they reach production.

๐Ÿš€

Pre-Deployment Checklist

All timestamps stored in UTC

Database columns, API responses, and internal data structures use UTC timestamps

Timezone conversion only for display

Local timezone conversion happens in the presentation layer, not business logic

DST transition testing completed

Tested spring forward (non-existent times) and fall back (ambiguous times) scenarios

Leap year handling verified

February 29th edge cases and leap year arithmetic tested

Timezone database up to date

IANA timezone database is current and deployment process includes updates

Input validation for time data

All user inputs and API endpoints validate date/time formats and ranges

Error handling for invalid times

Graceful handling of non-existent times, invalid dates, and parsing failures

Logging includes timezone information

All log timestamps include timezone info (preferably UTC)

๐Ÿ‘€

Code Review Checklist

๐Ÿšจ Red Flags to Watch For

โŒ

Naive datetime objects

Look for datetime objects without timezone information

datetime.now(), new Date("2024-03-10")
โŒ

Hardcoded timezone offsets

Avoid fixed offsets that don't account for DST changes

timestamp + (5 * 3600), utc_time - timedelta(hours=8)
โŒ

Local time arithmetic

Date/time arithmetic performed in local timezone

local_time + timedelta(hours=24)
โŒ

Ambiguous string parsing

Date strings without explicit format or timezone

Date.parse("01/02/2024"), strptime("2024-03-10 14:30")
โŒ

Timezone abbreviation usage

Using ambiguous timezone abbreviations instead of IANA names

"EST", "PST", "CST" instead of "America/New_York"

โœ… Good Patterns to Look For

โœ…

Explicit timezone specification

All datetime operations specify timezone explicitly

datetime.now(timezone.utc), DateTime.utc()
โœ…

UTC for calculations

All date arithmetic performed in UTC

utc_time + timedelta(hours=2)
โœ…

Safe timezone conversion

Using proper timezone conversion methods

.astimezone(), .setZone(), .withZoneSameInstant()
โœ…

Input validation

Proper validation of date/time inputs

if (!dt.isValid) throw new Error()
โœ…

DST-aware testing

Tests cover DST transition edge cases

test_spring_forward(), test_fall_back()
๐Ÿ”Œ

API Design Checklist

ISO 8601 format for all timestamps

Use standardized format: 2024-03-10T14:30:00.000Z

Always include timezone information

Either UTC (Z suffix) or explicit offset (+05:00)

Accept multiple input formats

Parse ISO 8601, Unix timestamps, and common formats gracefully

Validate timezone names

Accept only valid IANA timezone identifiers

Consistent error responses

Clear error messages for invalid dates, times, and timezones

Version API for timezone changes

Handle timezone database updates without breaking clients

๐Ÿ—„๏ธ

Database Design Checklist

All timestamps stored as UTC

Use TIMESTAMP WITH TIME ZONE or equivalent, set to UTC

Separate user timezone preferences

Store user timezone separately from timestamp data

Indexes on timestamp columns

Optimize queries that filter or sort by time

Audit trail with timestamps

created_at, updated_at columns for all important tables

Backup and recovery tested

Verify timestamp integrity across backup/restore operations

๐Ÿงช

Testing Checklist

Unit Tests

DST spring forward (non-existent times)
DST fall back (ambiguous times)
Leap year February 29th handling
Year 2038 problem (32-bit overflow)
Milliseconds vs seconds confusion
Invalid date/time input handling

Integration Tests

Cross-timezone data consistency
API endpoint timezone handling
Database timestamp storage/retrieval
Scheduled job execution during DST
Multi-timezone user scenarios
๐Ÿ“Š

Monitoring & Alerting Checklist

DST transition alerts

Monitor system behavior during spring forward and fall back

Timezone database update monitoring

Alert when IANA timezone database needs updating

Clock drift detection

Monitor server time synchronization with NTP

Invalid timestamp error tracking

Monitor and alert on parsing failures and invalid dates

Scheduled job execution monitoring

Verify cron jobs and scheduled tasks run correctly during DST

๐Ÿ“‹

Quick Reference

Golden Rules

  • โ€ข Store everything in UTC
  • โ€ข Convert to local time only for display
  • โ€ข Never do date arithmetic in local time
  • โ€ข Always specify timezone explicitly
  • โ€ข Test around DST transitions
  • โ€ข Use IANA timezone names, not abbreviations
  • โ€ข Validate all time-related inputs
  • โ€ข Handle non-existent and ambiguous times

Common Pitfalls

  • โ€ข Assuming 24-hour days (DST!)
  • โ€ข Mixing seconds and milliseconds
  • โ€ข Hardcoding timezone offsets
  • โ€ข Using naive datetime objects
  • โ€ข Ignoring leap years and leap seconds
  • โ€ข Parsing ambiguous date formats
  • โ€ข Not testing edge cases
  • โ€ข Forgetting timezone database updates