It's common knowledge that the number of days in a year is not constant.

Since the Earth doesn't orbit the Sun in exactly 365 days and it is impractical to not have a whole number of days in the year we allow our calendar seasons to become marginally desynchronised with astronomical seasons and every four years (more or less) have a year with an extra day in it.

This is called a leap year, and contains a leap day.

There's an analogous concept of a leap second to correct the discrepancy between the Earth's rotation about its axis and the number of seconds as measured by atomic clocks.

Leap seconds

On days with a positive leap second there is an extra second in the day. To minimise disruption this second officially happens at midnight.

As a result 23:59:60 is a valid time of day.

The average person is not likely to notice that, though computers will, and since computers run software written by humans they may not handle this very well.

The default handling of this in Linux when using CLOCK_REALTIME is that 23:59:59 lasts for two seconds.

This could cause issues for software that controls things like robot arms, since an instruction to rotate for 1 second would become rotate for 2 seconds.

An alternative, handled by using Google's time servers as your NTP server, is to smear the leap second across the whole day.

Since your computer typically has to deal with your clock drifting small corrections are regularly made anyway, so this is a neat solution.

This doesn't help if your computer normally has a very reliable clock, as any software written specifically to run on it will depend on this property which is not correct for a whole day every so often.

This could be a problem for specialist control software, but it's a more serious problem for authoritative NTP servers who can't use an upstream NTP server to do the time smearing for them.

To handle this there's CLOCK_TAI which will return 23:59:60.

The leap second adjustments are handled by adjtimex(2), applying a time smear if using Google's time servers, or inserting a leap second into the day.

With the discussion of CLOCK_TAI we have discussed all the clocks that measure the passage of time.

Another type of clock for measuring a different notion of time is the CPU clock, for accounting how much CPU a process or thread uses, which will be discussed at another time.

Leap seconds are inserted at 23:59:60 UTC, not local time. Some stock exchanges shut down briefly in the middle of 2015 rather than keep running across the leap second at the risk of timekeeping errors.
Comment by ben Fri Oct 20 14:35:46 2017