Week Number
Author Message
Week Number

I've converted the JavaScript week number code in jswkcalc.htm to Pascal
(& Delphi), and it is rather neater-looking (but slower) than the
previous.  Now in dateprox.pas (get mjd_date.zip, via SigLine 3, to
test).  I think it's OK.

procedure JSWN(const Opts : Options ; var N : shortint ;
var Y : integer ; M, D : byte) ;
(* jswkcalc:
function YMDtoYN(y, m, d) {
var P3D=259200000 ; var P7D=604800000
var s=Math.floor((Date.UTC(y,m-1,d)+P3D)/P7D);
var yy
with (new Date(s*P7D)) { yy=getFullYear() }
return [yy, 1+s-Math.floor((Date.UTC(yy,0,4)+P3D)/P7D)] }
"add 3 to date, then go to beginning of that week,
return first the true year of that date, return secondly one plus the
week-count of that minus the week-count of Jan 4 of that year" *)
var S : longint ;
const K = 77777777-1 ;
begin
S := (YMD_to_MJD(Opts, Y, M, D) + 3 + K) div 7 ;
MJD_to_YMD(Opts, S*7 - K, Y, M, D) ;
N := 1 + S - (YMD_to_MJD(Opts, Y, 1, 4) + 3 + K) div 7 ;
end {JSWN} ;

YMD_to_MJD & MJD_to_YMD can be any procedures for converting to/from a
true day count; K is large, to avoid div-of-negative; the odd 1 in K is
adjusted as necessary to get the phase-of-the-week (depends on origin of
daycount).  Opts chooses Greg/Juln &c.

--

Web <URL: http://www.*-*-*.com/ ; - FAQqish topics, acronyms & links.
PAS, EXE in <URL: http://www.*-*-*.com/ ; - see 00index.txt.
Do not Mail News to me.    Before a reply, quote with ">" or "> " (SoRFC1036)

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 1 post ]

Relevant Pages