number of week

JRS:  In article <3944A069.FCBE159F@N0_spamhccnet.nl> of Mon, 12 Jun
2000 10:33:45 seen in news:comp.lang.pascal.delphi.misc, Sam Francke

Quote
<s.j.francke@N0_spamhccnet.nl> wrote:
>Dr John Stockton wrote:
>> My http://www.merlyn.demon.co.uk/programs/dateprox.pas (BP7, D3) has
>> week number functions not looping in that manner.  One does not use
>> Delphi library routines, but routines coded elsewhere in the file.  One,
>> for Delphi only, uses SysUtils routines and ThuOne or Thu_One:

>> type NearYear = 1901..2099 ;

>> function ThuOne(const Y : NearYear) : byte ;
>> const Tbl : array [0..27] of byte =
>>   (7,5,4,3,2,7,6,5,4,2,1,7,6,4,3,2,1,6,5,4,3,1,7,6,5,3,2,1) ;
>> begin ThuOne := Tbl[Y mod 28] end {ThuOne} ;

>> function Thu_One(const Y : NearYear) : byte ;
>> begin Thu_One :=
>>     Succ((37 - (((Y+3) mod 28) * 5) div 4) mod 7) end {Thu_One} ;

>> procedure
>>   ISO_Week_NumD(var N : shortint ; var Y : integer ; const M, D : byte) ;
>> begin N :=
>>     (7+3+1 - Thu_One(Y) + Round(EncodeDate(Y, M, D)-EncodeDate(Y, 1, 1)))
>>     div 7 ;
>>   if N=0 then begin Dec(Y) ; ISO_Week_NumD(N, Y, 12, 31) end else
>>     if N=53 then
>>     if D>=Thu_One(Succ(Y))+(31-3) then begin Inc(Y) ; N := 1 end ;
>>   end {ISO_Week_NumD} ;

>> That is less tested than the non-Delphi version; but seems OK.

>Thank you very much, many things to study.

I have added two new versions to dateprox today, thanks to Claus
Tondering, the author of The Calendar FAQ.  One, as shown in
mjd_date.pas, is 25% quicker on average than the Pascal version of the
above (in BP7, on 486/33), but as yet does not return the Year.  The new
dateprox.pas will be uploaded soon, but not immediately.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 Web <URL: http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
 PAS, EXE in <URL: http://www.merlyn.demon.co.uk/programs/> - see 00index.txt.
 Do not Mail News to me.    Before a reply, quote with ">" or "> " (SoRFC1036)