Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #29048

Re: mktime

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.c
Subject Re: mktime
Date 2012-12-07 17:17 -0500
Organization A noiseless patient Spider
Message-ID <k9tpu9$ptf$1@dont-email.me> (permalink)
References <87vccf1clw.fsf@huddi.jernurt.dk> <k9qcil$oh$1@dont-email.me> <lnobi7ortk.fsf@nuthaus.mib.org> <k9saf7$jn$1@news.m-online.net> <k9tk5a$caq$1@news.m-online.net>

Show all headers | View raw


On 12/7/2012 3:39 PM, Heinrich Wolf wrote:
>
> "Heinrich Wolf" <invalid@invalid.invalid> schrieb im Newsbeitrag
> news:k9saf7$jn$1@news.m-online.net...
> ...
>> These may result in different values around a leap second (at the end
>> of some years) or around the transition from normal time to daylight
>> savings time or vice versa.
> ...
> My Fedora 14 man page for mktime tells me that leap seconds exist, but
> is there anybody out there who has seen them on a system?
>
> My Fedora 14 man page for mktime in German:
> ...
>        Die Elemente der Struktur tm sind:
>
>        tm_sec Die  Anzahl  der  Sekunden  nach der vollen Minute,
> normalerweise im Bereich 0 bis 59, jedoch in Ausnahmefällen bis 61 um
> Schaltsekunden zu
>               erlauben.
> ...
> Translated into English:
> ...
>        The elements of struct tm are:
>
>        tm_sec The number of seconds after the full minute, normally in
> the range 0 to 59, but in exceptional cases up to 61 in order to allow
> leap seconds.
> ...
>
> I searched for leap seconds on 2 different systems: Fedora 14 Linux, and
> Windows XP with Borland C++Builder 5.
> I expected the calculation localtime(mktime(1970-1-2 00-00-00) + 10000 *
> 24 * 60 * 60 seconds) to result in a tm struct with some odd seconds,
> but on both systems I got 1997-05-20 01-00-00

     I remember seeing the [0..61] range for tm_sec long ago, and
perhaps it still persists in some non-C documents.  Even in the
original 1989 ANSI C Standard, though, the range was [0..60] in
keeping with the fact that leap seconds are added (or removed)
one at a time, never two at once.

     As to the calculation -- well, timekeeping is complicated.
POSIX *defines* the day as 86400 seconds, intentionally ignoring
leap seconds (see <http://en.wikipedia.org/wiki/Unix_time>), so
we should not expect a C implementation based on POSIX time to
generate tm_sec==60.  The C Standard does not require the library
to overcome this problem:

	7.27.1p4: "The range and precision of times representable
	in clock_t and time_t are implementation-defined."

	7.27.2.4p3: "The time function returns the implementation’s
	*best approximation* [emphasis mine] to the current calendar
	time."

     Timekeeping and time calculation on POSIX and POSIX-like systems
is "close enough for jazz," sufficiently accurate for many purposes
but not astonishingly good.  C implementations don't have to do any
better (and on a strictly-conforming POSIX system, I guess they're
actually forbidden to do better).

-- 
Eric Sosman
esosman@comcast-dot-net.invalid

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

mktime Anders Wegge Keller <wegge@wegge.dk> - 2012-12-06 15:25 +0100
  Re: mktime James Kuyper <jameskuyper@verizon.net> - 2012-12-06 09:53 -0500
  Re: mktime Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-06 10:11 -0500
    Re: mktime Anders Wegge Keller <wegge@wegge.dk> - 2012-12-06 17:40 +0100
      Re: mktime Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-06 14:20 -0500
        Re: mktime Keith Thompson <kst-u@mib.org> - 2012-12-06 12:28 -0800
          Re: mktime Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-06 17:36 -0500
            Re: mktime Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-06 17:42 -0500
    Re: mktime Keith Thompson <kst-u@mib.org> - 2012-12-06 12:20 -0800
      Re: mktime Anders Wegge Keller <wegge@wegge.dk> - 2012-12-06 21:37 +0100
      Re: mktime "Heinrich Wolf" <invalid@invalid.invalid> - 2012-12-07 09:48 +0100
        Re: mktime James Kuyper <jameskuyper@verizon.net> - 2012-12-07 08:08 -0500
          Re: mktime "christian.bau" <christian.bau@cbau.wanadoo.co.uk> - 2012-12-07 09:23 -0800
            Re: mktime James Kuyper <jameskuyper@verizon.net> - 2012-12-07 13:14 -0500
            Re: mktime Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-07 13:46 -0500
            Re: mktime "Heinrich Wolf" <invalid@invalid.invalid> - 2012-12-07 19:59 +0100
            Re: mktime Robert Wessel <robertwessel2@yahoo.com> - 2012-12-07 15:50 -0600
        Re: mktime "Heinrich Wolf" <invalid@invalid.invalid> - 2012-12-07 21:39 +0100
          Re: mktime Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-07 17:17 -0500
            Re: mktime Keith Thompson <kst-u@mib.org> - 2012-12-07 17:50 -0800
              Re: mktime Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-08 08:34 -0500
          Re: mktime pacman@kosh.dhis.org (Alan Curry) - 2012-12-07 22:44 +0000
            Re: mktime "Heinrich Wolf" <invalid@invalid.invalid> - 2012-12-08 10:31 +0100
              Re: mktime pacman@kosh.dhis.org (Alan Curry) - 2012-12-08 20:50 +0000
                Re: mktime "Heinrich Wolf" <invalid@invalid.invalid> - 2012-12-09 11:39 +0100
                Re: mktime pacman@kosh.dhis.org (Alan Curry) - 2012-12-09 19:47 +0000
                Re: mktime "Heinrich Wolf" <invalid@invalid.invalid> - 2012-12-10 09:51 +0100
                Re: mktime sla29970@gmail.com - 2012-12-09 08:41 -0800

csiph-web