bug in mktime() normalization?

Paul Eggert eggert at twinsun.com
Thu Aug 21 07:41:04 UTC 1997


  Date: Tue, 19 Aug 97 14:13:13 -0400
  From: Tom Peterson (USG) <tomp at zk3.dec.com>

  In mktime(), or rather time2(), I noticed that a change was 
  made a while back which removed the following seconds normalization:

  ! 	if (yourtm.tm_sec >= SECSPERMIN + 2 || yourtm.tm_sec < 0)
  ! 		normalize(&yourtm.tm_min, &yourtm.tm_sec, SECSPERMIN);

  Instead, these seconds are now saved aside into saved_seconds and only 
  added back in after an appropriate match is found using the remaining 
  normalized data.

This was to handle leap seconds properly.  On systems that support
leap seocnds, it's incorrect to normalize the seconds count first,
since you don't know how many seconds there are per minute until you
determine which minutes you're talking about.  For example, with
leap second support, mktime should adjust an input value of
``1997-07-01 00:00:-1'' UTC (i.e. tm_sec == -1) so that it becomes
1997-06-30 23:59:60 UTC, but with the code above, mktime generated
1997-06-30 23:59:59 UTC which is incorrect.

  Here's what UNIX98 has to say regarding this:



More information about the tz mailing list