From: Jason Green Newsgroups: comp.os.msdos.djgpp Subject: Re: strftime: Need Help with Time Offsets Date: Thu, 11 Jan 2001 21:56:52 +0000 Organization: Customer of Energis Squared Lines: 33 Message-ID: References: NNTP-Posting-Host: modem-67.tellurium.dialup.pol.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: newsg1.svr.pol.co.uk 979250211 29787 62.136.43.67 (11 Jan 2001 21:56:51 GMT) NNTP-Posting-Date: 11 Jan 2001 21:56:51 GMT X-Complaints-To: abuse AT theplanet DOT net X-Newsreader: Forte Agent 1.7/32.534 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Esa A E Peuha 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.