[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]
Part1 - Part2 - Single Page
Top Document: [news.software.readers] trn newsreader FAQ, part 2: Advanced
Previous Document: News Headers
Next Document: ATKS: I want to set up a simple news archive. How can I run TRN non-interactively (e.g. as a cron job)?
-
Search the FAQ Archives
Part1 - Part2 - Single Page
Top Document: [news.software.readers] trn newsreader FAQ, part 2: Advanced
Previous Document: News Headers
Next Document: ATKS: I want to set up a simple news archive. How can I run TRN non-interactively (e.g. as a cron job)?
BLYC: Patches for "leap year bug"
Erez Zadok <ezk@news.cs.columbia.edu>, John Line <jml4@cus.cam.ac.uk>, Peter Kappesser <Peter_Kappesser@promail.com>, Anne Bennett <anne@alcor.concordia.ca> Since January 1, 1996 on some systems, every time users run trn, they may be asked whether they want to subscribe to new newsgroups which they have previously declined by answering 'n' or 'N'. The reason is that, as of the first second of 1996, trn miscomputed the number of leap years, and was therefore off by one whole day, reporting that the date of the news server was exactly 24 hours into the future, thus thinking that these "new" newsgroups could not have been seen at all. Either of two patches will fix the problem. The "simple patch" works until the year 2100, and is preferred by Wayne Davison (since it uses a simple division, instead of a loop, and he doesn't expect people to still be using trn at that time anyway). The "fancy patch" is accurate until the year 2400. Although the line numbers are for trn 3.6, the code will work in strn-0.9.2 at the appropriate place. SIMPLE PATCH THAT WORKS UNTIL 2100 Submitted by Miquel van Smoorenburg <miquels@debian.het.net> ---8<------8<------8<------8<---cut here--->8------>8------>8------>8--- ------- nntp.c ------- *** /tmp/da005NK Thu Jan 1 00:00:00 1970 --- nntp.c Wed Jan 3 20:43:11 1996 *************** *** 319,326 **** for (month--; month; month--) day += maxdays[month]; ! ss = ((((year-1970) * 365 + (year-1968)/4 + day - 1) * 24L + hh) * 60 ! + mm) * 60 + ss; return ss; } --- 319,326 ---- for (month--; month; month--) day += maxdays[month]; ! ss = ((((year-1970) * 365 + (year-1969)/4 + day - 1) * 24L + hh) * 60 ! + mm) * 60 + ss; return ss; } ---8<------8<------8<------8<---cut here--->8------>8------>8------>8--- FANCY PATCH THAT WORKS UNTIL 2400 Submitted by Paul Close <pdc@lunch.engr.sgi.com> ---8<------8<------8<------8<---cut here--->8------>8------>8------>8--- --- trn-3.6/nntp.c Fri Nov 18 22:01:23 1994 +++ nntp.c.leap Fri Jan 5 16:38:33 1996 @@ -285,12 +285,13 @@ /* This is a 1-relative list */ static int maxdays[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; +#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) time_t nntp_time() { char *s; - int year, month, day, hh, mm; + int year, month, day, hh, mm, y; time_t ss; nntp_command("XDATE" + (CompliantServer? 0 : 1)); @@ -306,11 +307,11 @@ s[4] = '\0'; year = atoi(s); - /* This simple algorithm will be valid until the year 2400 */ - if (year % 4) - maxdays[2] = 28; - else + if (isleap(year)) maxdays[2] = 29; + else + maxdays[2] = 28; + if (month < 1 || month > 12 || day < 1 || day > maxdays[month] || hh < 0 || hh > 23 || mm < 0 || mm > 59 || ss < 0 || ss > 59) @@ -319,8 +320,12 @@ for (month--; month; month--) day += maxdays[month]; - ss = ((((year-1970) * 365 + (year-1968)/4 + day - 1) * 24L + hh) * 60 - + mm) * 60 + ss; + for (y = 1970; y < year; y++) + if (isleap(y)) + day += 366; + else + day += 365; + ss += (((day - 1) * 24L + hh) * 60 + mm) * 60; return ss; } ---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Top Document: [news.software.readers] trn newsreader FAQ, part 2: Advanced
Previous Document: News Headers
Next Document: ATKS: I want to set up a simple news archive. How can I run TRN non-interactively (e.g. as a cron job)?
Part1 - Part2 - Single Page
[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]
Send corrections/additions to the FAQ Maintainer:
@tigerden.com (Peter J. Kappesser)
Last Update October 12 2008 @ 00:13 AM