Mail Archives: djgpp/2001/01/11/19:06:30
Esa A E Peuha <peuha AT cc DOT helsinki DOT fi> wrote:
> > Erm, sorry, this is not obvious to me. Although that's probably more
> > to do with damage suffered staring at date maths code. ;-)
>
> No wonder. :-) It's all pretty simple once you really understand it,
> but it can be mind-boggling before that.
For a student of mathematics perhaps. ;-)
> > I put your code into functions. Unfortunately, it sometimes gets the
> > week number wrong where week 52/53 overlaps into the new year.
>
> So it does. That's because I made a silly mistake (see below).
>
> > /* day belongs to last week of previous year */
> > return number_of_week (t->tm_wday,
> > t->tm_yday +
> > ((isleap(t->tm_year + TM_YEAR_BASE)) ?
> > 366:365));
>
> This, of course, needs to add the number of days in the previous year,
> so it should test for isleap(t->tm_year + TM_YEAR_BASE - 1).
Yep that fixes it, thanks. I'll put this together with what I have
already and post a patch to the djgpp-workers list.
> BTW, why
> is there an extra set of parentheses around isleap(...)?
Only because I generally prefer to place parentheses around the
condition just as if it were an `if' or `while' statement, I think
that makes the code easier to read.
- Raw text -