Computerphile
AI-assisted summary of The Problem with Time & Timezones - Computerphile — original source. Check the original for full context.
Source published:
Key ideas
- Writing custom time-handling logic is notoriously error-prone due to compounding edge cases, including fractional hour offsets, diverging Daylight Saving Time schedules, and geopolitical calendar shifts. (0:00)
- Geopolitical anomalies can instantly break software assumptions: Samoa excised an entire day (December 30, 2011) to cross the International Date Line, and overlapping populations in the West Bank observe different time zones within the same coordinates. (2:50)
- Fluctuations in Earth's rotation necessitate leap seconds (23:59:60), which can crash or desynchronize naive software systems expecting strictly 60-second minutes. (6:41)
- Google mitigates leap second synchronization failures using a 'leap smear' technique, dilating clock ticks by microseconds across a 24-hour window to prioritize monotonic continuity over absolute solar precision. (9:16)
Detailed notes
## Background Published by Computerphile on YouTube on December 30, 2013, this video features Tom Scott exploring the deceptively difficult task of building a web application that tracks elapsed time. The video description humorously poses how hard calculating elapsed seconds can be, framing time as something that twists and turns unpredictably and is certainly not to be trifled with.
## TL;DR Tom Scott illustrates the hidden complexity of date and time handling through the narrative of a developer building a seemingly simple web calculator. As the application encounters fractional time zones, conflicting Daylight Saving schedules, skipped calendar days like Samoa's date-line jump, and historic calendar transitions, simple arithmetic breaks down into chaotic edge cases. Celestial mechanics further complicate matters with unpredictable leap seconds, forcing modern infrastructure like Google to implement workarounds such as leap smears. Ultimately, Scott delivers a passionate warning to engineers: never attempt to write your own time-handling code, and instead rely entirely on established, battle-tested open-source libraries.
## Atmosphere & style The presentation carries the frantic, darkly comedic energy of a seasoned developer recounting a past trauma. Tom Scott speaks with rapid-fire delivery, expressive disbelief, and escalating exasperation, transforming dry computer science concepts into an engaging cautionary tale. Watching it feels like a descent down an inescapable rabbit hole of edge cases, shifting from cheerful overconfidence at the outset to total, humorous surrender by the conclusion.
## Bulletin - [00:00](https://www.youtube.com/watch?v=-5wpm-gesOY&t=0s) Writing custom time-handling logic is notoriously error-prone due to compounding edge cases, including fractional hour offsets, diverging Daylight Saving Time schedules, and geopolitical calendar shifts. - [02:50](https://www.youtube.com/watch?v=-5wpm-gesOY&t=170s) Geopolitical anomalies can instantly break software assumptions: Samoa excised an entire day (December 30, 2011) to cross the International Date Line, and overlapping populations in the West Bank observe different time zones within the same coordinates. - [06:41](https://www.youtube.com/watch?v=-5wpm-gesOY&t=401s) Fluctuations in Earth's rotation necessitate leap seconds (23:59:60), which can crash or desynchronize naive software systems expecting strictly 60-second minutes. - [09:16](https://www.youtube.com/watch?v=-5wpm-gesOY&t=556s) Google mitigates leap second synchronization failures using a 'leap smear' technique, dilating clock ticks by microseconds across a 24-hour window to prioritize monotonic continuity over absolute solar precision.
## Key takeaways - [00:00](https://www.youtube.com/watch?v=-5wpm-gesOY&t=0s) Developers should never attempt to implement custom time zone calculations from scratch. - [00:00](https://www.youtube.com/watch?v=-5wpm-gesOY&t=0s) Time zone offsets do not strictly adhere to integer hour increments, as demonstrated by South Australia's 9.5-hour and Nepal's 5.75-hour offsets. - [01:40](https://www.youtube.com/watch?v=-5wpm-gesOY&t=100s) Daylight Saving Time rules vary widely across jurisdictions, with countries switching on different weekends rather than globally synchronized dates. - [01:40](https://www.youtube.com/watch?v=-5wpm-gesOY&t=100s) Opposite hemispheres invert seasonal clock changes, causing Southern Hemisphere clocks to advance for spring while Northern Hemisphere clocks move backward in autumn. - [02:50](https://www.youtube.com/watch?v=-5wpm-gesOY&t=170s) Geopolitical decisions can eliminate calendar dates, such as Samoa skipping December 30, 2011, to align trade with Australia and New Zealand. - [02:50](https://www.youtube.com/watch?v=-5wpm-gesOY&t=170s) Short-notice governmental decrees, like Libya's 2013 clock change cancellation with two days' notice, leave software maintainers unable to distribute patches in time. - [02:50](https://www.youtube.com/watch?v=-5wpm-gesOY&t=170s) Geographic coordinates alone cannot determine local time, as seen in the West Bank where Israeli and Palestinian populations follow separate time zones in the same territory. - [05:14](https://www.youtube.com/watch?v=-5wpm-gesOY&t=314s) Historical calendar transitions from the Julian to Gregorian calendar omitted blocks of days at differing times across countries, ranging from 1752 in Britain to post-1917 in Russia. - [05:14](https://www.youtube.com/watch?v=-5wpm-gesOY&t=314s) Historical English civil years began on March 25th (Lady Day) rather than January 1st, meaning January and February belonged to the prior numerical year. - [06:41](https://www.youtube.com/watch?v=-5wpm-gesOY&t=401s) Earth's irregular rotational speed caused by tectonic and atmospheric dynamics forces the periodic introduction of leap seconds creating a 23:59:60 timestamp. - [06:41](https://www.youtube.com/watch?v=-5wpm-gesOY&t=401s) Standard Unix epoch timestamps fail to fully abstract away astronomical discrepancies between UTC civil time and atomic time scales. - [06:41](https://www.youtube.com/watch?v=-5wpm-gesOY&t=401s) The only reliable engineering practice for handling time is using established, community-maintained open-source time libraries. - [09:16](https://www.youtube.com/watch?v=-5wpm-gesOY&t=556s) Google's 'leap smear' resolves distributed database race conditions by spreading the extra leap second across 24 hours in fractional microsecond adjustments. - [09:16](https://www.youtube.com/watch?v=-5wpm-gesOY&t=556s) For distributed transactional systems, maintaining monotonic sequence continuity is fundamentally more important than absolute solar accuracy.
## Detailed walkthrough ### [00:00](https://www.youtube.com/watch?v=-5wpm-gesOY&t=0s) The Naive Time Calculator and Fractional Offsets
Every software developer eventually runs into the challenge of handling time, but Tom Scott cautions that he cannot provide an easy solution—only a cautionary tale. He frames the scenario through a hypothetical developer building an apparently trivial web application: a tool that takes a user-supplied date and time and calculates how many seconds in the past that event occurred. Initially, the application seems straightforward, but the developer decides to enhance it by adding a drop-down menu allowing users to select an hour offset ahead of or behind Greenwich Mean Time, making it possible to compare the current time in New York with five days prior in London. The developer believes the problem is solved cleanly with simple integer offsets.
```mermaid flowchart TD accTitle: Escalation of Time Tracking Edge Cases accDescr: Flowchart showing how simple time calculations break down as edge cases accumulate from offsets to astronomical shifts. subgraph Basic["Basic Variations"] A["Integer Hour Offsets"] --> B["Fractional Offsets<br>(Australia, Nepal)"] B --> C["Daylight Saving Shifts<br>(Opposite Hemispheres)"] end subgraph GeoPolitical["Political & Historical Shifts"] C --> D["Date Line Skips & Border Overlaps<br>(Samoa, West Bank)"] D --> E["Calendar Reforms & New Year Shifts<br>(Julian/Gregorian, March 25)"] end subgraph Astronomical["Astronomical Anomaly"] E --> F["Leap Seconds<br>(23:59:60)"] end ```
The system quickly unravels as international users begin reporting problems. A user from Australia reaches out to inform the developer that their local time is offset from Greenwich by 9½ hours, forcing the programmer to implement a bespoke exception. Shortly thereafter, an inquiry arrives from Nepal, where local time sits at 5¼ hours ahead of Greenwich. After patching in yet another special case, the developer consults what is supposed to be the canonical database of international time zones to ensure every global region is represented, assuming the problem has finally been laid to rest.
- Tom Scott’s direct warning to developers: “I can tell you why you really should never, ever deal with time zones if you can help it.” - Initial assumption: Time zones differ by whole, predictable one-hour increments relative to Greenwich. - Fractional offsets encountered: South Australia / Northern Territory (9 hours 30 minutes) and Nepal (5 hours 45 minutes).
[01:40](https://www.youtube.com/watch?v=-5wpm-gesOY&t=100s) Daylight Saving Time and Geographic Inversions
The fragile offset logic collapses completely with the arrival of autumn. A user from England contacts the developer to report that all calculations are off by precisely one hour. The programmer defends the code, arguing that Daylight Saving Time (DST) changes were already recorded and accounted for based on their own local calendar rules. The English user points out the fatal flaw: different countries adjust their clocks on entirely different weekends, with the United Kingdom shifting its clocks an entire week earlier than the developer's home region.
Confronted with the realization that DST rules vary by nation, the developer pulls down a transition table to programmatically track individual national switch dates. Any relief is short-lived. A user from the Southern Hemisphere calls to explain that their clocks do not move backward in autumn during the developer's season; instead, their spring arrives in November, requiring clocks to spring forward while the Northern Hemisphere falls back. At this point, the developer is left staring longingly at a bottle, realizing their once-simple program is rapidly turning into an unmanageable thicket of branch logic.
- England's correction to the developer's naive DST implementation: “We shift our clocks back a week before you do.” - Hemispheric inversion: While Northern Hemisphere countries set clocks back in autumn, Southern Hemisphere countries advance their clocks during their spring in November.
[02:50](https://www.youtube.com/watch?v=-5wpm-gesOY&t=170s) Political Realities, Skipped Days, and Borders
The edge cases escalate from cyclical schedule adjustments to geopolitical decisions that erase entire calendar days. Samoa provides a dramatic example: situated in the Pacific right near the International Date Line, the nation decided in late 2011 to align its commerce with its major trading partners in Australia and New Zealand. To do so, Samoa jumped from December 29, 2011, directly to December 31, 2011, completely skipping December 30 and shifting from twenty-four hours behind to hours ahead of Greenwich. Historical anomalies further complicate matters: during World War II, the United Kingdom adopted British Double Summer Time, running two hours ahead of Greenwich despite Greenwich being located within its own borders.
Tom admits that his storytelling mirrors his own agonizing past experiences with programming time systems. National time alterations occur far more frequently than programmers expect, often shifting multiple times within a single year due to changes in government. In late 2013, the Libyan government announced with only a couple of days' notice that it would abandon its planned clock change, leaving software vendors with zero time to distribute an operating system patch and throwing every computer in Libya an hour out of sync. Geopolitical conflict produces even stranger anomalies: in the West Bank, Israeli and Palestinian populations living in the exact same physical territory observe different time zones concurrently based on their governing authorities, making it mathematically impossible to determine the correct time from geographic coordinates alone.
- Tom Scott reflecting on his own developer trauma: “Because I've done this before and it's really, really frustrating.” - The West Bank spatial conflict: “Now you have two populations of people in the same location who are following different time zones.” - Samoa's border jump: Completely eliminated December 30, 2011, going straight from December 29 to December 31. - British Double Summer Time (BDST): Kept the UK two hours ahead of Greenwich during WWII. - Libya (2013): Canceled daylight saving changes on two days' notice, desynchronizing all operating systems nationwide.
[05:14](https://www.youtube.com/watch?v=-5wpm-gesOY&t=314s) Historical Calendar Shifts and New Year Anomalies
Just as modern political quirks are patched into the code, historical researchers introduce a whole new layer of temporal chaos. A historian attempting to calculate intervals dating back to the 18th century requests support for the transition between the Julian and Gregorian calendars. The switch did not involve lost time in an absolute sense, but rather a direct calendar skip where a block of days was excised overnight to realign with the solar year. The programmer adds the calendar tables, creating a fragile spaghetti codebase, only to receive a call from a Russian historian pointing out that Russia did not adopt the Gregorian calendar until after the 1917 revolution in the 20th century—and that the specific dates omitted vary based on jurisdiction.
The timeline fractures even further when British historical conventions are factored in. Prior to the mid-18th century calendar reforms, the English legal and civil year did not commence on January 1st; it began on Lady Day, March 25th. Under this system, March 24, 924, was immediately followed on the next day by March 25, 925. Conversely, December 31, 924, transitioned into January 1, 924, because the calendar year continued running until late March. Attempting to parse historic dates sequentially without knowing the specific local convention yields completely invalid math.
- Tom Scott highlighting the chronological disorientation of early English calendars: “Just to blow your mind there.” - Julian-to-Gregorian transition: Countries skipped blocks of days at different points in history (e.g., Britain in 1752, Russia in the early 20th century). - Historic English New Year: Prior to adoption of January 1, the official year turned over on March 25th (Lady Day), causing January and February to share the numeric year of the preceding autumn.
[06:41](https://www.youtube.com/watch?v=-5wpm-gesOY&t=401s) Leap Seconds and Astronomical Discrepancies
The ultimate disruption comes from celestial mechanics. An astrophysicist informs the programmer of an impending leap second, caused by the fact that the Earth does not rotate at a constant velocity. Tectonic plate movements, shifting core dynamics, and atmospheric friction cause planetary rotation to fluctuate unpredictably. To keep solar time aligned with civil time, the International Astronomical Union and international timekeepers periodically mandate the insertion of an extra second. Instead of rolling over smoothly from 23:59:59 to 00:00:00, standard clocks display the anomalous timestamp 23:59:60, creating a 61-second minute that crashes naive software expecting minutes to strictly comprise 60 seconds.
```mermaid flowchart LR accTitle: Leap Second Handling Discrepancy accDescr: Diagram illustrating how UTC handles leap seconds via an extra second compared to a hard repeat or astronomical time. subgraph UTC_Standard["Standard UTC Rollover"] U1["23:59:58"] --> U2["23:59:59"] U2 --> U3["23:59:60 (Leap Second)"] U3 --> U4["00:00:00"] end subgraph Flawed_Systems["Crash / Desync Risk"] F1["Repeats Second<br>(23:59:59 twice)"] F2["Drifts 1s Out of Sync"] end U3 -.->|"Poor Handling"| Flawed_Systems ```
Developers often assume that using a standard Unix timestamp—counting the continuous elapsed seconds since the epoch of January 1, 1970—eliminates this headache, but it fails to solve the underlying problem. Coordinated Universal Time (UTC) incorporates leap seconds and requires dealing with non-standard timestamps, while purely astronomical and atomic time scales omit leap seconds and steadily diverge from civil clock time so that astronomers can aim telescopes accurately. Tom emphasizes that the only sane path for a software engineer is complete surrender: abandon the hubris of writing custom date-time logic, rely exclusively on heavily vetted, open-source time libraries built by previous generations of engineers, and never inspect the underlying code again.
- Tom Scott’s absolute rule for date-time programming: “You look at the people who have dealt with this before, the people who have built the spaghetti code, and you thank them very much for making it open source, and you give them credit, and you take what they have made and you put it in your program, and you never ever look at it again.” - Astronomical cause: Irregular terrestrial rotation driven by mantle movements, tectonic drift, and internal dynamics. - The leap second artifact: The clock reads `23:59:60` before advancing to `00:00:00`. - Software failure modes: Applications either crash, freeze, repeat a second, or fall permanently out of synchronization.
[09:16](https://www.youtube.com/watch?v=-5wpm-gesOY&t=556s) Google's Leap Smear: Continuity over Strict Accuracy
For massive distributed systems handling millions of financial or database transactions every second, the sudden addition of a 61st second or repeating an existing second can cause critical race conditions and data corruption. If two events are recorded with identical timestamps or out of chronological sequence, distributed databases cannot reliably determine causality. To solve this, Google developed an infrastructure technique known as the "leap smear."
Instead of halting the system clock or introducing a sudden 23:59:60 timestamp, Google gradually dilates time across its entire server fleet. Over the course of the day leading up to the leap second, Google's Network Time Protocol servers adjust each clock tick by tiny microsecond fractions. While this means their internal clocks might drift up to half a second away from true solar or atomic time during the transition, every server in the cluster remains synchronized with the others. For distributed computer science, maintaining strict monotonic continuity and sequence ordering takes precedence over absolute fidelity to the Earth's astronomical position.
- Core philosophy of the leap smear: “Having continuity is more important than actually having accurate time.” - Implementation mechanism: Rather than dropping or duplicating a whole second at midnight, clocks run microseconds slower across an entire 24-hour period. - Operational trade-off: Internal clocks may temporarily sit half a second out of sync with external civil time, but monotonic ordering across all internal distributed databases is preserved.
## Notable quotes > [09:16](https://www.youtube.com/watch?v=-5wpm-gesOY&t=556s) Having continuity is more important than actually having accurate time. — Tom Scott
> [00:00](https://www.youtube.com/watch?v=-5wpm-gesOY&t=0s) I can tell you why you really should never, ever deal with time zones if you can help it. — Tom Scott
## Mentioned Tom Scott, Sean Riley, Brady Haran, Computerphile, Numberphile, Google, International Astronomical Union, Greenwich Mean Time, Coordinated Universal Time, Unix timestamp, Network Time Protocol, British Double Summer Time, Julian calendar, Gregorian calendar, Lady Day, International Date Line, Samoa, Libya, Nepal, Australia, West Bank
## Video description A web app that works out how many seconds ago something happened. How hard can coding that be? Tom Scott explains how time twists and turns like a twisty-turny thing. It's not to be trifled with!
A Universe of Triangles: http://www.youtube.com/watch?v=KdyvizaygyY LZ Compression in Text: http://www.youtube.com/watch?v=goOa3DGezUA Characters, Symbols and the Unicode Miracle: http://www.youtube.com/watch?v=MijmeoH9LT4
More from Tom Scott: http://www.youtube.com/user/enyay and https://twitter.com/tomscott
http://www.facebook.com/computerphile https://twitter.com/computer_phile
This video was filmed and edited by Sean Riley.
Computerphile is a sister project to Brady Haran's Numberphile. See the full list of Brady's video projects at: http://bit.ly/bradychannels
[Source](https://www.youtube.com/watch?v=-5wpm-gesOY)