2012-11-01

The Trouble with Leap Seconds, Part 1

"What a funny watch! It tells the day of the month, and it doesn't tell what o'clock it is!" "Why should it?"
Alice's Adventures in Wonderland

Like any other piece of software (and information generally), this comes with NO WARRANTY.

Earlier this summer the IERS added another leap second to the clock, a semi-regular adjustment in the timekeeping world intended to keep the sun more or less overhead at midday in most parts of the world. This made a lot of people very angry and has been widely regarded as a bad idea. Several proponents of consistent time and other people who fear change regularly lobby to either have the leap second replaced with a leap hour that happens every few centuries or removed altogether.

Until such plans actually come to pass, however, leap seconds are what we have and leap seconds are what we must handle.

The gold standard for timekeeping in the Internet era is the Network Time Protocol, or NTP. NTP was developed by David Mills and has gone through several revisions over the years to allow two or more machines to maintain a fairly accurate synchronization of the clock that each system uses for all the great things for which we need computer clocks to be accurate in the first place. Sadly, NTP and its various implementations are all pretty much terrible at handling the insertion of leap seconds to the UTC time scale. Despite Mills himself attesting to the contrary, empirical evidence suggests that injecting leap seconds still causes huge service interruptions. It's easy enough to blame the service vendors for writing terrible, buggy code that doesn't graciously handle leap seconds. It's easier still for developers to blame the operating system, the time scale, David Mills himself, leap seconds, or Robert Bunsen and Gustav Kirchhoff, the two chemists who are credited with discovering cesium and thus allowing our current era of precise timekeeping to be possible.

Playing this blame game is just cursing the dark. I choose instead to light a candle.

On the surface there isn't anything incredibly difficult about the idea of leap seconds but the devil, they say, is in the details. The programmers of the world who are just desperately trying to get their problem solved are handicapped by the POSIX standard, that woefully designed-by-committee document that allows GNU tools and BSDs to work almost but never quite exactly consistently among different operating systems. POSIX outlines the Single Unix Specification, which unfortunately shows an enormous amount of dogmatic shortsightedness in that it defines a day as having only and ever exactly 86,400 seconds. In other words, POSIX decrees that the world works differently from factual, observable phenomena. This level of brokenness is up there with the Vatican insisting that the Earth is at the center of the universe and all heavenly bodies orbit it. Ironically, the SUS concept of timekeeping directly contradicts parts of the Gregorian calendar with regards to leap years. It can't be relied upon to measure time accurately because it defines a time scale and a calendar that don't exist.

Next time: a broken clock is monotonically right never times a day.

1 comment:

Winsling said...

While you're at it, it's worth mentioning that the leap second spec allows negative leap seconds. It's never actually been done, so it's sure to cause all kinds of problems if it ever is.