#140 Python for data 6.7 min
Python Dates and Time Zones: 5 Bugs Reproduced
Add one day to a London time across the clock change, and only 23 real hours pass.
A day without a clock change
Copy the code folder first. On Windows, pin tzdata as the video does. In run.py, in the dst mode, change the start date from datetime(2026, 3, 28, 9, 0, tzinfo=LONDON) to datetime(2026, 4, 10, 9, 0, tzinfo=LONDON). Predict the real hours between, then run python run.py dst. When I ran it, Python said 1 day, 0:00:00 and the real hours were 24.0.
A hint
Nothing changes the London clocks between 10 and 11 April.
Remove fold
In run.py, in the fold mode, change second = first.replace(fold=1) to second = first. Predict the UTC time on the fold=1 line and the real hours between. Then run python run.py fold. When I ran it, both lines showed UTC 00:30:00 and the real hours between were 0.0.
A hint
Without fold=1, Python picks the earlier of the two 01:30 times.
Break the parsed Z string
In run.py, in the naive mode, change the string '2026-03-30T08:00Z' to '2026-03-30T09:00Z'. London is on BST on 30 March, so predict what the 'parsed Z matches' line will print. Then run python run.py naive. When I ran it, it printed False.
A hint
BST is one hour ahead of UTC, so 09:00 in London is not 09:00 UTC.
Another country's clock change
In run.py, in the dst mode, change the start to datetime(2026, 3, 7, 9, 0, tzinfo=NEW_YORK). Predict the 'real hours between' line. Then run python run.py dst. When I ran it, the start was EST, the next day was EDT, and the real hours between were 23.0. The video tested only two zones, so treat other zones as something to check.
A hint
The name of the zone abbreviation changes on the +1 day line.
These tasks are for you to try on your own machine. Nothing is checked or saved.
What this does not show
Two zones and a few made-up 2026 times on one Windows run; it does not test other countries' rules, databases or calendars.