home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / hcshdemo.zip / csh-os2.zip / SAMPLES / CALDATE.CSH < prev    next >
Text File  |  1993-09-28  |  932b  |  32 lines

  1. #    Calculate the calendar date (month, day, year) corresponding to
  2. #    a Julian day number.  (Negative years are B.C.)
  3. #    Based on algorithms published in Computer Language magazine,
  4. #    December, 1990.  Used with permission.
  5.  
  6. proc caldate(jdate)
  7.     local a, b, c, d, e, z, alpha, month, day, year
  8.     set month = January February March April May June ^
  9.         July August September October November December
  10.     @ z = jdate + 1
  11.     # Cope with the Gregorian calendar reform.
  12.     if (z < 2299161) then
  13.         @ a = z
  14.         # Intercept years B.C.
  15.         if (z < 1721423) @ a -= 366
  16.     else
  17.         @ alpha = (z - 1867216.25)//36524.25
  18.         @ a = z + 1 + alpha - alpha//4
  19.     end
  20.     @ b = a + 1524
  21.     @ c = (b - 122.1)//365.25
  22.     @ d = floor(365.25 * c)
  23.     @ e = (b - d)//30.6001
  24.     @ day = b - d - floor(30.6001 * e)
  25.     @ e -= e < 14 ? 2 : 14
  26.     @ month = month[e]
  27.     if ((year = e > 1 ? c - 4716 : c - 4715) == 0) @ year--
  28.     return "$month $day $year"
  29. end
  30.  
  31. caldate $argv
  32.