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  
 
 [ 1 post ] 

 Relevant Pages 

1. Program for Week number

2. Date to Week Number

3. Date to Week Number

4. Calculate week-number

5. Week-numbers

6. Program for Week number

7. How to get the number of the week.

8. Day in week and week in year calculations, oops!

9. Week function needed

10. Weeks of searching - Turbo Access?

11. GUARANTEED 2-5 LBS WEIGHT LOSS PER WEEK

12. Learning Pascal in 8 weeks-help!

 

 
Powered by phpBB® Forum Software