Subject: bin/5833: [PATCH] pom Y2K bug
To: None <gnats-bugs@gnats.netbsd.org>
From: Joseph Myers <jsm@octomino.demon.co.uk>
List: netbsd-bugs
Date: 07/24/1998 17:30:25
>Number:         5833
>Category:       bin
>Synopsis:       [PATCH] pom Y2K bug
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jul 24 10:35:01 1998
>Last-Modified:
>Originator:     Joseph Samuel Myers
>Organization:
Trinity College, University of Cambridge, UK
>Release:        NetBSD-current of 1998-07-11
>Environment:
	
[
System: Linux octomino 2.0.35 #1 Tue Jul 14 19:09:50 UTC 1998 i586 unknown
Architecture: i586
]
>Description:

This bug was found in the course of checking the Linux port of the
NetBSD games for year 2000 compliance.

pom uses the isleap macro from <tzfile.h> on a tm_year value (year -
1900), meaning that it will incorrectly not treat the year 2000 as a
leap year and will be off by one day in 2001.

>How-To-Repeat:

Give pom a date in the year 2001 and observe that the phase given is
off by one day (untested) (depends on the accuracy of the algorithm
used).  Giving times just before and after the end of 2000 shows the
problem without needing to know the actual phase of the Moon at that
time:

$ pom 978307199
The Moon is Waxing Crescent (32% of Full)
$ pom 978307200
The Moon is Waxing Crescent (24% of Full)

>Fix:

--- pom/pom.c	Sat Jun 13 11:07:00 1998
+++ pom+/pom.c	Fri Jul 24 17:17:53 1998
@@ -106,7 +106,7 @@
 	days = (GMT->tm_yday + 1) + ((GMT->tm_hour +
 	    (GMT->tm_min / 60.0) + (GMT->tm_sec / 3600.0)) / 24.0);
 	for (cnt = EPOCH; cnt < GMT->tm_year; ++cnt)
-		days += isleap(cnt) ? 366 : 365;
+		days += isleap(cnt + 1900) ? 366 : 365;
 	today = potm(days) + .5;
 	(void)printf("The Moon is ");
 	if ((int)today == 100)

>Audit-Trail:
>Unformatted: