Leap Seconds and Unix Time
How leap seconds interact with Unix timestamps. Learn why Unix time ignores them, the smearing approach, and what the 2035 abolition means for developers.
Concept
leap second
Detailed Explanation
A leap second is an occasional one-second adjustment added to UTC to keep it synchronized with the Earth's slowing rotation. Since 1972, 27 leap seconds have been inserted. Unix time, by definition, does not count leap seconds — it always assumes each day has exactly 86,400 seconds. This creates a subtle discrepancy between Unix timestamps and true elapsed time.
How a leap second plays out:
On June 30, 2012, a leap second was inserted at midnight:
23:59:59 UTC → Unix time 1341100799
23:59:60 UTC → (leap second, Unix time still 1341100799)
00:00:00 UTC → Unix time 1341100800
The leap second 23:59:60 maps to the same Unix timestamp as 23:59:59. This means that during a leap second, Unix time effectively pauses for one second. Two distinct moments in real time share the same timestamp.
Leap second smearing:
Google, Amazon, and most cloud providers use "leap smearing" instead of inserting a discrete leap second. They spread the extra second over a longer period (typically 24 hours), slightly slowing or speeding their clocks. This avoids the sudden discontinuity that has historically caused crashes in systems like Linux kernels, Cassandra clusters, and Reddit's infrastructure.
Google smear: noon-to-noon, ±0.5s distributed over 24h
Amazon (AWS): midnight-to-midnight, similar distribution
Impact on developers:
For most applications, leap seconds are irrelevant. Unix timestamps smooth them over, and cloud providers smear them away. However, if you are building systems that require sub-second accuracy (financial trading, scientific instrumentation, GPS receivers), you must account for them. The TAI (International Atomic Time) timescale counts every second including leap seconds, and the difference between TAI and UTC equals the accumulated leap seconds (currently 37 seconds).
The future: In November 2022, the General Conference on Weights and Measures voted to abolish leap seconds by 2035. After that, the discrepancy between atomic time and astronomical time will be allowed to grow, eliminating this edge case for future developers.
Use Case
High-frequency trading systems cannot use Unix timestamps for ordering events during a leap second, as two distinct trades could receive the same timestamp, requiring alternative sequencing mechanisms.