home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / qtawk / date.exp < prev    next >
Text File  |  1990-04-23  |  1KB  |  40 lines

  1. # QTAwk utility functions for computing Julian Day Number from calender date
  2. # and reverse
  3. # (C) Copyright 1990 Terry D. Boldt, All Rights Reserved
  4. # gregorian/julian calender flag.
  5. #   TRUE == julian
  6. #   FALSE == gregorian --> current calender system
  7. #
  8. # greg_jul = FALSE;  # --> current calender system
  9.  
  10. # function to convert year/month/day into julian day number
  11. function jdn(year,month,day) {
  12.     local yr;
  13.     local pfac = 0.6;
  14.     local ljdn;
  15.  
  16.     yr = year + (month - 3.0) / 12.0;
  17.     ljdn = int(367.0 * yr + pfac) - (2 * int(yr)) + int(yr/4.0)
  18.        + int(day) + 1721117;
  19.     if ( !greg_jul ) ljdn += -int(yr/100.0) + int(yr/400.0) + 2;
  20.     return ljdn;
  21. }
  22.  
  23. #  function to convert jdn to yr/mo/dy.
  24. function _caln(cjdn,date) {
  25.     local n, ic, np, npp, mp;
  26.  
  27.     n = int(cjdn) - 1721119;
  28.     ic = (n - 0.2)/36524.25;
  29.     if ( greg_jul ) np = n + 2; else np = n + ic - (ic / 4L);
  30.     date[1] = int((np - 0.2)/365.25);
  31.     npp = np - int(365.25 * date[1]);
  32.     mp = (npp - 0.5)/30.6;
  33.     date[3] = int(npp + 0.5 - 30.6 * mp);
  34.     if ( mp <= 9 ) date[2] = mp + 3;
  35.       else {
  36.     date[1] += 1.0;
  37.     date[2] = mp - 9;
  38.     }
  39. }
  40.