Subject: lib/10521: y2k bug in mktime
To: None <gnats-bugs@gnats.netbsd.org>
From: Wolfgang Rupprecht <wolfgang@wsrcc.com>
List: netbsd-bugs
Date: 07/05/2000 22:58:16
>Number:         10521
>Category:       lib
>Synopsis:       mktime doesn't like years > 100
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jul 05 22:59:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Wolfgang Rupprecht
>Release:        NetBSD-current Jun 9 2000
>Organization:
W S Rupprecht Computer Consulting, Fremont CA
>Environment:
	
System: NetBSD capsicum.wsrcc.com 1.4ZB NetBSD 1.4ZB (WSRCC) #0: Fri Jun 9 15:31:49 PDT 2000 wolfgang@capsicum.wsrcc.com:/v/src/netbsd/NetBSD-current/usr/src/sys/arch/i386/compile/WSRCC i386


>Description:
	there is a y2k bug in mktime.  It refuses to convert tm
        structs where the year is set to 1996.  The number 96 works 
	just fine.

	marked medium/serious only because of the y2k stigma.

>How-To-Repeat:

(gdb) p tm
$2 = {
  tm_sec = 50, 
  tm_min = 39, 
  tm_hour = 18, 
  tm_mday = 22, 
  tm_mon = 5, 
  tm_year = 1996, 
  tm_wday = 0, 
  tm_yday = 0, 
  tm_isdst = 0, 
  tm_gmtoff = 0, 
  tm_zone = 0x804bc21 "GMT"
}
(gdb) p mktime(&tm)
$3 = -1
(gdb) p tm.tm_year = 96
$4 = 96
(gdb) p tm
$5 = {
  tm_sec = 50, 
  tm_min = 39, 
  tm_hour = 18, 
  tm_mday = 22, 
  tm_mon = 5, 
  tm_year = 96, 
  tm_wday = 0, 
  tm_yday = 0, 
  tm_isdst = 0, 
  tm_gmtoff = 0, 
  tm_zone = 0x804bc21 "GMT"
}
(gdb) p mktime(&tm)
$6 = 835497590

Notice it works for a year of "96" but not a year of "1996".

>Fix:
	damned if I know.  (I can't even remember how many days in any
particualar month.  I'm gonna write code to do it all the way back to
the epoch?)

#ifdef __NetBSD__
		if (tm.tm_year > 100)
		    tm.tm_year %= 100;
#endif

>Release-Note:
>Audit-Trail:
>Unformatted: