## Posted By

Scooter on 05/19/08

## Who likes this?

2 people have marked this snippet as a favorite

# Calculating Easter

/ Published in: ASP

Function library for calculation of Easter and related ecclesiastical holidays.

`<%    ' ASP Easter Calculation Library    '    ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.    '    ' This work is licensed under the Creative Commons Attribution License. To view    ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or    ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California    ' 94305, USA.    '    ' This function library allows calculation of the following ecclesiastical holidays:    ' Ash Wednesday, Palm Sunday, Good Friday, Easter, Ascension Day, and Pentecost.    '    ' Refer to Wikipedia for information on the purpose of these holidays..     ' Determine the date of Easter for a given year.    function dateEaster(someYear)        Dim goldenNumber        Dim solarCorrection        Dim lunarCorrection        Dim paschalFullMoon        Dim dominicalNumber        Dim difference        Dim dayEaster         goldenNumber = (someYear Mod 19) + 1         if someYear <= 1752 then            ' Julian calendar            dominicalNumber = (someYear + (someYear / 4) + 5) Mod 7            paschalFullMoon = (3 - (11 * goldenNumber) - 7) Mod 30        else            ' Gregorian calendar            dominicalNumber = (someYear + (someYear / 4) - (someYear / 100) + (someYear / 400)) Mod 7            solarCorrection = (someYear - 1600) / 100 - (someYear - 1600) / 400            lunarCorrection = (((someYear - 1400) / 100) * 8) / 25            paschalFullMoon = (3 - 11 * goldenNumber + solarCorrection - lunarCorrection) Mod 30        end if         do until dominicalNumber > 0            dominicalNumber = dominicalNumber + 7        loop         do until paschalFullMoon > 0            paschalFullMoon = paschalFullMoon + 30        loop         if paschalFullMoon = 29 or (paschalFullMoon = 28 and goldenNumber > 11) then            paschalFullMoon = paschalFullMoon - 1        end if         difference = (4 - paschalFullMoon - dominicalNumber) Mod 7         if difference < 0 then            difference = difference + 7        end if         dayEaster = paschalFullMoon + difference + 1         if dayEaster < 11 then            ' Easter occurs in March.            dateEaster = DateSerial(someYear, 3, dayEaster + 21)        else            ' Easter occurs in April.            dateEaster = DateSerial(someYear, 4, dayEaster - 10)        end if    end function     ' Determine the date of Good Friday for a given year.    ' Requires dateEaster()    function dateGoodFriday(someYear)        dateGoodFriday = DateAdd("d", -2, dateEaster(someYear))    end function     ' Determine the date of Palm Sunday for a given year.    ' Requires dateEaster()    function datePalmSunday(someYear)        datePalmSunday = DateAdd("d", -7, dateEaster(someYear))    end function     ' Determines the date of Ash Wednesday for a given year.    ' Requires dateEaster()    function dateAshWednesday(someYear)        dateAshWednesday = DateAdd("d", -46, dateEaster(someYear))    end function     ' Deteremines the date of Ascension Day for a given year.    ' Requires dateEaster()    function dateAscensionDay(someYear)        dateAscensionDay = DateAdd("d", 39, dateEaster(someYear))    end function     ' Determines the date of Pentecost for a given year.    ' Requires dateEaster()    function datePentecost(someYear)        datePentecost = DateAdd("d", 49, dateEaster(someYear))    end function     ' Unit tests    ' Dim testYear    ' testYear = 2008    ' Response.Write "Ash Wednesday: " & dateAshWednesday(testYear) & "<br>"    ' Response.Write "Palm Sunday: " & datePalmSunday(testYear) & "<br>"    ' Response.Write "Good Friday: " & dateGoodFriday(testYear) & "<br>"    ' Response.Write "Easter: " & dateEaster(testYear) & "<br>"    ' Response.Write "Ascension Day: " & dateAscensionDay(testYear) & "<br>"    ' Response.Write "Pentecost: " & datePentecost(testYear) & "<br>"%>`