Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev Fix leap year handling for years 2100 and greater.
details: https://anonhg.NetBSD.org/src/rev/9b97fbc0bb65
branches: trunk
changeset: 347137:9b97fbc0bb65
user: jakllsch <jakllsch%NetBSD.org@localhost>
date: Mon Aug 15 15:51:39 2016 +0000
description:
Fix leap year handling for years 2100 and greater.
I can not explain why this works and the existing code doesn't.
Maybe it has something to do with leap years happening at the end of a
four year period and not at the beggining, and there being no year 0?
diffstat:
sys/dev/clock_subr.c | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
diffs (60 lines):
diff -r 74b1935bce4d -r 9b97fbc0bb65 sys/dev/clock_subr.c
--- a/sys/dev/clock_subr.c Mon Aug 15 14:45:31 2016 +0000
+++ b/sys/dev/clock_subr.c Mon Aug 15 15:51:39 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: clock_subr.c,v 1.26 2014/12/22 18:09:20 christos Exp $ */
+/* $NetBSD: clock_subr.c,v 1.27 2016/08/15 15:51:39 jakllsch Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@@ -50,7 +50,7 @@
#ifdef _KERNEL
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock_subr.c,v 1.26 2014/12/22 18:09:20 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock_subr.c,v 1.27 2016/08/15 15:51:39 jakllsch Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -67,8 +67,8 @@
#define FEBRUARY 2
/* for easier alignment:
- * time from the epoch to 2000 (there were 7 leap years): */
-#define DAYSTO2000 (365*30+7)
+ * time from the epoch to 2001 (there were 8 leap years): */
+#define DAYSTO2001 (365*31+8)
/* 4 year intervals include 1 leap year */
#define DAYS4YEARS (365*4+1)
@@ -96,14 +96,14 @@
if (is_leap_year(year) && dt->dt_mon > FEBRUARY)
days++;
- if (year < 2000) {
+ if (year < 2001) {
/* simple way for early years */
for (i = POSIX_BASE_YEAR; i < year; i++)
days += days_per_year(i);
} else {
/* years are properly aligned */
- days += DAYSTO2000;
- year -= 2000;
+ days += DAYSTO2001;
+ year -= 2001;
i = year / 400;
days += i * DAYS400YEARS;
@@ -155,9 +155,9 @@
/* Day of week (Note: 1/1/1970 was a Thursday) */
dt->dt_wday = (days + 4) % 7;
- if (days >= DAYSTO2000) {
- days -= DAYSTO2000;
- dt->dt_year = 2000;
+ if (days >= DAYSTO2001) {
+ days -= DAYSTO2001;
+ dt->dt_year = 2001;
i = days / DAYS400YEARS;
days -= i*DAYS400YEARS;
Home |
Main Index |
Thread Index |
Old Index