home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / EASTER.PRG < prev    next >
Text File  |  1991-08-16  |  4KB  |  132 lines

  1. /*
  2.  * File......: EASTER.PRG
  3.  * Author....: Paul Tucker
  4.  * Date......: $Date:   15 Aug 1991 23:05:28  $
  5.  * Revision..: $Revision:   1.2  $
  6.  * Log file..: $Logfile:   E:/nanfor/src/easter.prv  $
  7.  * 
  8.  * While I can say that I wrote the program, the algorithm is from Donald
  9.  * Knuth's The Art of Computer Programming, Section 1.3.2.  So, the source
  10.  * code is an original work by Paul Tucker and is placed in the public 
  11.  * domain
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log:   E:/nanfor/src/easter.prv  $
  17.  * 
  18.  *    Rev 1.2   15 Aug 1991 23:05:28   GLENN
  19.  * Forest Belt proofread/edited/cleaned up doc
  20.  * 
  21.  *    Rev 1.1   14 Jun 1991 19:51:42   GLENN
  22.  * Minor edit to file header
  23.  * 
  24.  *    Rev 1.0   01 Apr 1991 01:01:16   GLENN
  25.  * Nanforum Toolkit
  26.  *
  27.  */
  28.  
  29.  
  30. /*  $DOC$
  31.  *  $FUNCNAME$
  32.  *     FT_EASTER()
  33.  *  $CATEGORY$
  34.  *     Date/Time
  35.  *  $ONELINER$
  36.  *     Return the date of Easter
  37.  *  $SYNTAX$
  38.  *     FT_EASTER( <xYear> ) -> dEdate
  39.  *  $ARGUMENTS$
  40.  *     xYear can be a character, date or numeric describing the year
  41.  *     for which you wish to receive the date of Easter.
  42.  *  $RETURNS$
  43.  *     The actual date that Easter occurs.
  44.  *  $DESCRIPTION$
  45.  *     Returns the date of Easter for any year after 1582 up to Clipper's
  46.  *     limit which the manual states is 9999, but the Guide agrees with
  47.  *     the actual imposed limit of 2999.
  48.  *
  49.  *     This function can be useful in calender type programs that indicate
  50.  *     when holidays occur.
  51.  *  $EXAMPLES$
  52.  *     dEdate := FT_EASTER( 1990 )     && returns 04/15/1990
  53.  *  $END$
  54.  */
  55.  
  56.  
  57. FUNCTION FT_EASTER (nYear)
  58.   local nGold, nCent, nCorx, nCorz, nSunday, nEpact, nMoon,;
  59.         nMonth := 0, nDay := 0, lCent := __SetCentury( .t. )
  60.  
  61.   // --------------------------------
  62.   // NOTE: __SetCentury() is internal
  63.   // --------------------------------
  64.  
  65.   IF VALTYPE (nYear) == "C"
  66.      nYear = VAL(nYear)
  67.   ENDIF
  68.  
  69.   IF VALTYPE (nYear) == "D"
  70.      nYear = YEAR(nYear)
  71.   ENDIF
  72.  
  73.   IF VALTYPE (nYear) == "N"
  74.      IF nYear > 1582
  75.  
  76.         * <<nGold>> is Golden number of the year in the 19 year Metonic cycle
  77.         nGold = nYear % 19 + 1
  78.  
  79.         * <<nCent>> is Century
  80.         nCent = INT (nYear / 100) + 1
  81.  
  82.         * Corrections:
  83.         * <<nCorx>> is the no. of years in which leap-year was dropped in order
  84.         * to keep step with the sun
  85.         nCorx = INT ((3 * nCent) / 4 - 12)
  86.  
  87.         * <<nCorz>> is a special correction to synchronize Easter with the moon's
  88.         * orbit.
  89.         nCorz = INT ((8 * nCent + 5) / 25 - 5)
  90.  
  91.         * <<nSunday>> Find Sunday
  92.         nSunday = INT ((5 * nYear) / 4 - nCorx - 10)
  93.  
  94.         * Set Epact <<nEpact>> (specifies occurance of a full moon)
  95.         nEpact = INT ((11 * nGold + 20 + nCorz - nCorx) % 30)
  96.  
  97.         IF nEpact < 0
  98.            nEpact += 30
  99.         ENDIF
  100.  
  101.         IF ((nEpact = 25) .AND. (nGold > 11)) .OR. (nEpact = 24)
  102.            ++nEpact
  103.         ENDIF
  104.  
  105.         * Find full moon - the <<nMoon>>th of MARCH is a "calendar" full moon
  106.         nMoon = 44 - nEpact
  107.  
  108.         IF nMoon < 21
  109.            nMoon += 30
  110.         ENDIF
  111.  
  112.         * Advance to Sunday
  113.         nMoon = INT (nMoon + 7 - ((nSunday + nMoon) % 7))
  114.  
  115.         * Get Month and Day
  116.         IF nMoon > 31
  117.            nMonth = 4
  118.            nDay = nMoon - 31
  119.         ELSE
  120.            nMonth = 3
  121.            nDay = nMoon
  122.         ENDIF
  123.      ENDIF
  124.   ELSE
  125.      nYear = 0
  126.   ENDIF
  127.  
  128.   set century (lCent)
  129.  
  130. RETURN  CTOD (RIGHT ("00"+LTRIM (STR (nMonth)),2) + "/" +;
  131.          RIGHT ("00"+LTRIM (STR (INT (nDay))) ,2) + "/" +STR (nYear,4))
  132.