[ntp:questions] Leap second question

Terje Mathisen "terje.mathisen at tmsw.no" at ntp.org
Wed Mar 20 19:22:26 UTC 2013

Stephen Yu wrote:
> Hello,
> In the dev release ntp-dev-4.2.7p361, the file ntp_timer.c has the
> following code to set "sys_leap".
> if (leapsec > 0) { leapsec--; if (leapsec == 0) { sys_leap =
> LEAP_NOWARNING; ......................... } else { if (leapsec <
> DAY) sys_leap = LEAP_ADDSECOND; if (leap_tai > 0) sys_tai = leap_tai
> - 1; } }
> The question is why "sys_leap = LEAP_ADDSECOND" is unconditional. Is
> this based on the prior knowledge that earth always rotates slower?
> In other word, could it ever be "sys_leap = LEAP_DELSECOND"?

You are correct, this is a bug, but it will almost certainly never hit 
us, since everything so far indicates that leap seconds will never be 

The fix is relatively obvious, the most important tweak is that a 
negative leap second must be applied one second earlier, i.e. at 
23:59:59 instead of midnight, so the countdown will be one second less.


- <Terje.Mathisen at tmsw.no>
"almost all programming can be viewed as an exercise in caching"

More information about the questions mailing list