diff options
author | danny <danny@FreeBSD.org> | 1999-01-12 19:37:32 +0000 |
---|---|---|
committer | danny <danny@FreeBSD.org> | 1999-01-12 19:37:32 +0000 |
commit | e3baab147a5a4449d245f7dbb19b8d6c6d1fb377 (patch) | |
tree | 4cb17362766e1aaf84aeba9474f8f001b6aa8bb4 | |
parent | a602dc10e4e8a6c927c6c2c7f1a5a3bf76c50c3b (diff) | |
download | FreeBSD-src-e3baab147a5a4449d245f7dbb19b8d6c6d1fb377.zip FreeBSD-src-e3baab147a5a4449d245f7dbb19b8d6c6d1fb377.tar.gz |
Fix leap year calculations, including 2000. The code was broken for all
years!
Reviewed by: <thepish@freebsd.org>, <ishisone@sra.co.jp>
-rw-r--r-- | usr.sbin/xntpd/parse/util/dcfd.c | 10 | ||||
-rw-r--r-- | usr.sbin/xntpd/parse/util/testdcf.c | 3 |
2 files changed, 9 insertions, 4 deletions
diff --git a/usr.sbin/xntpd/parse/util/dcfd.c b/usr.sbin/xntpd/parse/util/dcfd.c index 3898071..0acfa72 100644 --- a/usr.sbin/xntpd/parse/util/dcfd.c +++ b/usr.sbin/xntpd/parse/util/dcfd.c @@ -68,7 +68,7 @@ MUST DEFINE ONE OF "HAVE_TERMIOS" or "HAVE_TERMIO" #endif #ifndef dysize -#define dysize(_x_) (((_x_) % 4) ? 365 : (((_x_) % 400) ? 365 : 366)) +#define dysize(_x_) (((_x_) % 4) ? 365 : (((_x_) % 100) ? 366 : ((_x_) % 400 ? 365 : 366 ))) #endif #define timernormalize(_a_) \ @@ -761,7 +761,8 @@ dcf_to_unixtime(clock, cvtrtc) */ t = (clock->year - 1970) * 365; t += (clock->year >> 2) - (1970 >> 2); - t -= clock->year / 400 - 1970 / 400; + t -= clock->year / 100 - 1970 / 100; + t += clock->year / 400 - 1970 / 400; /* month */ if (clock->month <= 0 || clock->month > 12) @@ -1587,9 +1588,10 @@ main(argc, argv) -tt.tv_usec; /* - * output interpreted DCF77 data + * output interpreted DCF77 data. DCF77 gives us a YY year + * but dcf_to_unixtime() adds the century, so print YYYY. */ - PRINTF(offsets ? "%s, %2d:%02d:%02d, %d.%02d.%02d, <%s%s%s%s> (%c%d.%06ds)" : + PRINTF(offsets ? "%s, %2d:%02d:%02d, %d.%02d.%4d, <%s%s%s%s> (%c%d.%06ds)" : "%s, %2d:%02d:%02d, %d.%02d.%02d, <%s%s%s%s>", wday[clock.wday], clock.hour, clock.minute, i, clock.day, clock.month, diff --git a/usr.sbin/xntpd/parse/util/testdcf.c b/usr.sbin/xntpd/parse/util/testdcf.c index 219b7c3..bd5ea88 100644 --- a/usr.sbin/xntpd/parse/util/testdcf.c +++ b/usr.sbin/xntpd/parse/util/testdcf.c @@ -451,6 +451,9 @@ main(argc, argv) if (rtc == CVT_OK) { + /* We are only supplied two digits of the year, by the + * clock, so we'll just print two digits. + */ printf("%s, %2d:%02d:%02d, %d.%02d.%02d, <%s%s%s%s>", wday[clock.wday], (int)clock.hour, (int)clock.minute, (int)i, (int)clock.day, (int)clock.month, |