Blog Stéphane Bortzmeyer: Getting TAI time on a Debian machine

submited by
Style Pass
2024-04-17 07:00:03

It should work by default but, apparently, on some operating systems like Debian, it does not: to get the TAI time, you need a small configuration change. I document it here for myself or for people which will use a search engine and find this page.

TAI is useful because, unlike UTC, it never repeats a second, neither it misses one (UTC does, because of leap seconds). This makes it convenient, for instance for Internet servers. But how to get TAI time on a Debian machine?

The official answer is that when you use clock_gettime in a C program or time.clock_gettime in a Python one, you need to pass the option CLOCK_TAI. One can easily check that, on a Debian stable machine (version 12.5), it does not work: you get the same value with CLOCK_TAI or CLOCK_REALTIME (the typical clock, set on UTC).Unfortunately, no error code will tell you that something was wrong.

It seems that the kernel (which manages the clock and asnwers to clock_gettime) knows only UTC and, to convert to TAI, it needs to know the offset (currently 37 seconds). Debian has a file to do so, a leap seconds table, in /usr/share/zoneinfo/leap-seconds.list. This file contains all the information necessary to get TAI from UTC. But someone has to read it and to inform the kernel. This is typically done by ntpd. But it is not done by default, this is why the above test failed.

Leave a Comment