Inconsistancy between mktime and system time accross leapsecond

Garrett Wollman wollman at csail.mit.edu
Sat Aug 6 16:59:38 GMT 2005


<<On Sat, 06 Aug 2005 00:16:20 -0600 (MDT), "M. Warner Losh" <imp at bsdimp.com> said:

> mktime, however, when fed a leap second says that it is the first
> second of the first day of the month (which is the second that gets
> repeated).  posix is silent on what, exactly, to do with leap
> seconds.

Actually, POSIX is not silent.  It says they are to be ignored.  From
XBD section 4.4:

	As represented in seconds since the Epoch, each and every day
	shall be accounted for by exactly 86400 seconds.

You can model this as the POSIX epoch advancing by one second for
every leap second inserted (and similarly for deletions).

> It gives a formula that seems to support mktime's return value.
> However, since leap seconds are undefined in posix's time_t epoch, a
> case can be made for other values.

A case has been made, which has repeatedly been rejected by the POSIX
committee.  If you specify 23:59:60Z, a POSIX implementation *must*
normalize it to 00:00:00 the following day.  If you don't care about
POSIX compliance, then the code already supports what you want, by
encoding the leap-second tables into the timezone files.  See
src/share/zoneinfo/Makefile.  You'll want to add calls to time2posix()
and posix2time() to ntpd to adjust kernel times appropriately.

-GAWollman



More information about the freebsd-standards mailing list