Easter date or Easter Sunday is the Sunday, following the first full moon after the Vernal Equinox (= the 21st of March). This full moon is also referred to as: PASCHAL FULL MOON.
This Easter-routine uses Julian Day Number calculations, which has 3 advantages:
1. Easter-related holidays can easily be found too, e.g. Good Friday = Easter minus 2.
2. Once we have found the Julian Day Number for Paschal Full Moon, it's easy to find the next Sunday. Don't use difficult 'algebraic' formulas here, but simply add 1 (day) until the result is a Sunday.
3. Initially PFM is returned as the number of days elapsed since March 1. If this number is greater than 31, PFM is in April. However, using JDN you don't need to care about this. Simply pretend that March has more than 31 days. Example: 'March 32', written as Julian(year, 3, 32), equals April 1 or Julian(year, 4, 1)
[This message has been edited by Egbert Zijlema (edited April 22, 2000).]
This Easter-routine uses Julian Day Number calculations, which has 3 advantages:
1. Easter-related holidays can easily be found too, e.g. Good Friday = Easter minus 2.
2. Once we have found the Julian Day Number for Paschal Full Moon, it's easy to find the next Sunday. Don't use difficult 'algebraic' formulas here, but simply add 1 (day) until the result is a Sunday.
3. Initially PFM is returned as the number of days elapsed since March 1. If this number is greater than 31, PFM is in April. However, using JDN you don't need to care about this. Simply pretend that March has more than 31 days. Example: 'March 32', written as Julian(year, 3, 32), equals April 1 or Julian(year, 4, 1)
Code:
' =============================================================================== ' Source code: PowerBASIC for Windows ' Compiler: PBDLL60 ' Author: [email protected] ' Copyright status: Public Domain ' Purpose: Calculate Easter for a given year ' =============================================================================== #COMPILE EXE #INCLUDE "WIN32API.INC" FUNCTION Julian(BYVAL year AS INTEGER, _ BYVAL month AS INTEGER, _ BYVAL day AS INTEGER) AS LONG LOCAL Elapsed AS LONG, InvalidLeaps AS INTEGER, ValidLeaps AS INTEGER, dMonths AS INTEGER IF month < 3 THEN ' January or February? month = month + 12 ' 13th or 14th month .... DECR year ' .... of prev. year END IF Elapsed = INT((year + 4712) * 365.25) ' days in years elapsed InvalidLeaps = year \ 100 ' substract century leapdays ValidLeaps = year \ 400 ' re-add valid ones dMonths = INT(30.6 * (month - 1) + .2) ' days of months elapsed + adjustment FUNCTION = Elapsed - InvalidLeaps + _ ValidLeaps + dMonths + day END FUNCTION FUNCTION JulToDate(BYVAL Jul AS LONG) AS STRING LOCAL st AS SYSTEMTIME, szText AS ASCIIZ * 255 Jul = Jul + 68569 help& = 4 * Jul \ 146097 Jul = Jul - ((146097 * help& + 3) \ 4) TempYear& = 4000 * (Jul + 1) \ 1461001 Jul = Jul - (1461 * TempYear& \ 4) + 31 TempMonth& = 80 * Jul \ 2447 st.wDay = Jul - (2447 * TempMonth& \ 80) st.wMonth = TempMonth& + 2 - (12 * (TempMonth& \ 11)) st.wYear = 100 * (help& - 49) + TempYear& + (TempMonth& \ 11) GetDateFormat %LOCALE_USER_DEFAULT, %DATE_LONGDATE, st, BYVAL %NULL, szText, SIZEOF(szText) FUNCTION = szText END FUNCTION FUNCTION PaschalFullMoon(year AS INTEGER) AS LONG LOCAL Century AS INTEGER, temp AS INTEGER, PFM AS INTEGER Century = year \ 100 temp = (Century - 15) \ 2 temp = temp + 202 temp = temp - 11 * (year MOD 19) SELECT CASE Century CASE 21, 24, 25, 27 TO 32, 34, 35 DECR temp CASE 33, 36, 37, >38 temp = temp - 2 END SELECT temp = temp MOD 30 PFM = temp + 21 IF (temp = 29) OR _ (temp = 28 AND year MOD 19 > 10) THEN DECR PFM FUNCTION = Julian(year, 3, PFM) END FUNCTION FUNCTION EasterSunday(year AS INTEGER) AS LONG LOCAL start AS LONG, Sun AS BYTE Sun = 6 start = PaschalFullMoon(year) DO INCR start LOOP UNTIL start MOD 7 = Sun FUNCTION = start END FUNCTION FUNCTION GoodFriday(year AS INTEGER) AS LONG FUNCTION = EasterSunday(year) - 2 END FUNCTION FUNCTION EasterMonday(year AS INTEGER) AS LONG FUNCTION = EasterSunday(year) + 1 END FUNCTION FUNCTION AscensionDay(year AS INTEGER) AS LONG FUNCTION = EasterSunday(year) + 39 END FUNCTION FUNCTION WhitSunday(year AS INTEGER) AS LONG FUNCTION = EasterSunday(year) + 49 END FUNCTION FUNCTION WhitMonday(year AS INTEGER) AS LONG FUNCTION = EasterSunday(year) + 50 END FUNCTION FUNCTION PBMAIN() AS LONG LOCAL WhichYear AS INTEGER, caption AS STRING WhichYear = 2000 caption = "Easter " + TRIM$(STR$(WhichYear)) + " by Egbert Zijlema" MSGBOX "Paschal Full Moon in " + TRIM$(STR$(WhichYear)) + " is " + _ JulToDate(PaschalFullMoon(WhichYear)) + CHR$(46, 13) + _ "The first Sunday after this date - " + _ JulToDate(EasterSunday(WhichYear)) + " - is Easter" + CHR$(46, 13) + _ "Other Easter-related holidays are:" + CHR$(13, 9) + _ "Good Friday: " + JulToDate(GoodFriday(WhichYear)) + CHR$(46, 13, 9) + _ "Easter Monday: " + JulToDate(EasterMonday(WhichYear)) + CHR$(46, 13, 9) + _ "Ascension Day: " + JulToDate(AscensionDay(WhichYear)) + CHR$(46, 13, 9) + _ "Whit Sunday: " + JulToDate(WhitSunday(WhichYear)) + CHR$(46, 13, 9) + _ "Whit Monday: " + JulToDate(WhitMonday(WhichYear)) + ".", 64, caption END FUNCTION
[This message has been edited by Egbert Zijlema (edited April 22, 2000).]
Comment