tags:

views:

604

answers:

2

My time.h has the following definition of tm:

struct tm {
    int tm_sec;  /* seconds after the minute [0-60] */
    int tm_min;  /* minutes after the hour [0-59] */
    int tm_hour; /* hours since midnight [0-23] */
    ...
}

I just noticed that they document tm_sec as ranging between 0-60 inclusive. I've always assumed it ranged from 0-59 just like tm_min. I've certainly never seen a clock read 10:37:60...

Do you think this is just a documentation bug left over from this 90's era Berkley-originated file?

Or is there something more subtle going on that I'm unaware of?

+26  A: 

Leap seconds are the reason for this:

A leap second is a plus or minus one-second adjustment to the Coordinated Universal Time (UTC) time scale that keeps it close to mean solar time.

When a positive leap second is added at 23:59:60 UTC, it delays the start of the following UTC day (at 00:00:00 UTC) by one second, effectively slowing the UTC clock.

Kyle Cronin
+1: beat me by 23 seconds. And your guess is correct.
dwc
@dwc, mind editing the answer with some evidence?
Frank Krueger
http://www.opengroup.org/onlinepubs/009695399/basedefs/time.h.html and lots of other places tell about this.
dwc
a quote from the C standard would be nice
anon
@Neil: The C99 standard says this in a footnote: "The range [0,60] for tm_sec allows for a positive leap second."
Michael Burr
@michael - thanks!
anon
And interestingly, the C90 standard says: "The range [0,61] for tm_sec allows for as many as two leap seconds." - What happened in that decade? Is there no longer a need for a second leap second?
Michael Burr
@michael "The formal definition of UTC does not permit double leap seconds, so all mention of double leap seconds has been removed, and the range shortened from the former [0,61] seconds seen in previous versions of POSIX."
Kyle Cronin
hehe, nice observation. i feel c++1x will specify range as [0,6x] to allow for as many as 10 leap seconds oO
Johannes Schaub - litb
Or 0x10 leap seconds, if "x" turns out to be a placeholder for a hex digit ;-)
Steve Jessop
Someone involved with the C90 standard heard that "there can be up to two leap seconds in a year" and misinterpreted it to mean that they could both occur at once.
dan04
+8  A: 

The man page for ctime explains that this is about leap seconds:

tm_sec: The number of seconds after the minute, normally in the range 0 to 59, but can be up to 60 to allow for leap seconds.

sth