At the end of 2016 timekeepers added an extra second to the time we use to track our everyday activities. This is needed to match the astronomical time, measured through the Earth's slightly irregular rotation frequency, to the exact duration of a second defined through our atomic clocks. There are a number of ways for computers to handle this leap-second event. To see them in practice I configured four computers to record the event over the hours and seconds the adjustment took place. The results, which you can see in the video below, were very different from what I expected.
Three computers were running Debian GNU/Linux 8.6 (jessie) 3.16.0, and one was running the current release of FreeBSD 12.0. The computers marked with NTP were configured to synchronize their clocks with NTP (network time protocol) servers over the internet. These instruct them to add a second before midnight by repeating the Unix timestamp (seconds since 1970-01-01) of the last second. This is the number you see in the Unix row.
Because a second that is repeated with the same timestamp can be confusing, organizations such as Akamai, Amazon, Bloomberg, Google, and Microsoft implement a different strategy. They allow the leap second to be gradually introduced over many hours. For example, Google smears the time difference over twenty hours: half a second is added before midnight and half after midnight. The computer marked NTP Google was configured to use the time from
time.google.com, which is supposed to implement this type of smear.
The computer marked TAI (Temps Atomique International) was configured to run on International Atomic Time. This non-standard configuration advances the Unix time over the leap seconds and then uses specially crafted time-zone files to display the correct time. This makes its timestamps, which in 2016 ran 26 seconds ahead of the standard Unix time, incompatible with other systems. For example, this difference will be a problem in file creation times and other timestamps stored in shared file systems, file archives, revision control systems, and databases. On this system the leap second appears as 23:59:60. Because its time is not automatically synchronized with NTP, you will see that its clock drifts as time goes by.
The leap second is inserted at the same time all over the world, at 23:59:59 UTC. In the video I show
Two things in the video demonstrate things working as expected. (Jump to 1:33 in the video to see them.)
On two other counts, the results were quite different from what I expected.
My take from this exercise is that the handling of the leap second is tricky and it requires thorough and difficult testing.
In retrospect I should have run on each host the command
ntpq -c 'rv 0 leap' to query NTP on whether a leap second was announced to it.
I also attempted to record the leap second handling on a Microsoft Windows and a Mac OS X computer, but failed to get them work reliably by the end of the year.
The code I used to record the events and produce the animation is available on GitHub.Read and post comments, or share through
Last modified: Sunday, January 1, 2017 10:50 pm
Unless otherwise expressly stated, all original material on this page created by Diomidis Spinellis is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.