Correct definition of leap year. Make yeartonum and numtoyear use

full years so that year 2000 is correctly counted as a leap year.

Now NetBSD under SIMH picks up correct time-of-day clock value.  It
used to be a day behind, since 2000 - 1900 = 100 and naive leap year
test wouldn't count it as a leap year.
This commit is contained in:
uwe 2010-11-19 03:31:24 +00:00
parent b0f3f04a67
commit 5bb781f731
2 changed files with 7 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: clock.h,v 1.7 2009/12/12 14:44:09 tsutsui Exp $ */
/* $NetBSD: clock.h,v 1.8 2010/11/19 03:31:24 uwe Exp $ */
/*
* Copyright (c) 1996 Ludd, University of Lule}, Sweden.
* All rights reserved.
@ -37,7 +37,7 @@
/*
* Time constants. These are unlikely to change.
*/
#define IS_LEAPYEAR(y) (((y % 4) == 0) && (y % 100))
#define IS_LEAPYEAR(y) ((((y % 4) == 0) && ((y % 100) != 0)) || ((y % 400) == 0))
#define SEC_PER_MIN (60)
#define SEC_PER_HOUR (SEC_PER_MIN * 60)

View File

@ -1,4 +1,4 @@
/* $NetBSD: clock.c,v 1.53 2010/07/01 19:50:12 ragge Exp $ */
/* $NetBSD: clock.c,v 1.54 2010/11/19 03:31:24 uwe Exp $ */
/*
* Copyright (c) 1995 Ludd, University of Lule}, Sweden.
* All rights reserved.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.53 2010/07/01 19:50:12 ragge Exp $");
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.54 2010/11/19 03:31:24 uwe Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -199,18 +199,18 @@ yeartonum(int y)
{
int n;
for (n = 0, y -= 1; y > 69; y--)
for (n = 0, y -= 1; y > 1969; y--)
n += SECPERYEAR(y);
return n;
}
/*
* Converts tick number to a year 70 ->
* Converts tick number to a year 1970 ->
*/
int
numtoyear(int num)
{
int y = 70, j;
int y = 1970, j;
while(num >= (j = SECPERYEAR(y))) {
y++;
num -= j;