From: Jonathan Sergent <sergent@IO.COM>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] tiny bug in Acme News
Date: Sat, 28 Jul 2001 20:31:05 -0700 [thread overview]
Message-ID: <20010729033044.0EF8E199F4@mail.cse.psu.edu> (raw)
In-Reply-To: <E15Qh8O-0000FD-00@000pri026.bresnanlink.net>
On Saturday, July 28, 2001, at 08:07 PM, crdevilb@mtu.edu wrote:
> /acme/news/src/news.c:119
> if(1 <= j && j <= 31)
> should be
> if(1 <= j && j <= 31 && !d)
>
> or it will report the date as the current hour.
There are actually more problems than that if you look at the different
formats in use in an average (?) newsgroup. There are things with
timezone specifiers and such. A few months ago, I hacked my fixdate()
to:
char*
fixdate(char *s)
{
char *f[10], *m, *t, *wd, tmp[40];
int d, i, j, nf, hh, mm, mn, yr;
nf = tokenize(s, f, nelem(f));
wd = nil;
d = 0;
m = nil;
t = nil;
yr = 0;
mn = 0;
for(i=0; i<nf; i++){
for(j=0; j<7; j++)
if(cistrncmp(day[j], f[i], 3)==0)
wd = day[j];
for(j=0; j<12; j++)
if(cistrncmp(mon[j], f[i], 3)==0) {
m = mon[j];
mn = j;
}
while (f[i][0] && f[i][0] == '0')
f[i]++;
j = atoi(f[i]);
if(strchr(f[i], ':'))
t = f[i];
else if(f[i][0] == '+')
continue;
else if((d == 0) && (1 <= j && j <= 31))
d = j;
else if ((d != 0) && (j > 0)) {
if (j < 70)
yr = j + 2000;
else if (j < 100)
yr = j + 1900;
else if (j > 1970)
yr = j;
}
}
if(d==0 || m==nil || t==nil)
return nil;
hh = strtol(t, 0, 10);
mm = strtol(strchr(t, ':')+1, 0, 10);
if (wd == nil) {
Tm tm = { 0, mm, hh, d, mn, yr - 1900, 0, 0, "", 0 };
if (yr == 0 || mn == 0)
return nil;
wd = day[localtime(tm2sec(&tm))->wday];
}
sprint(tmp, "%s %d %s %d:%.2d", wd, d, m, hh, mm);
return estrdup(tmp);
}
I might have changed more than this function, but I can't remember. The
whole thing is a little ugly.
next prev parent reply other threads:[~2001-07-29 3:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-07-29 3:07 crdevilb
2001-07-29 3:31 ` Jonathan Sergent [this message]
2001-07-30 17:50 ` [9fans] lucent not the bright light it used to be matt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20010729033044.0EF8E199F4@mail.cse.psu.edu \
--to=sergent@io.com \
--cc=9fans@cse.psu.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).