Posted By

Scooter on 05/19/08


Tagged

DateTime


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ShadowKing
ckayra


Calculating Easter


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2008/03/calculating-easter.html

Function library for calculation of Easter and related ecclesiastical holidays.

  1. <%
  2. ' ASP Easter Calculation Library
  3. '
  4. ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
  5. '
  6. ' This work is licensed under the Creative Commons Attribution License. To view
  7. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  8. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  9. ' 94305, USA.
  10. '
  11. ' This function library allows calculation of the following ecclesiastical holidays:
  12. ' Ash Wednesday, Palm Sunday, Good Friday, Easter, Ascension Day, and Pentecost.
  13. '
  14. ' Refer to Wikipedia for information on the purpose of these holidays..
  15.  
  16. ' Determine the date of Easter for a given year.
  17. function dateEaster(someYear)
  18. Dim goldenNumber
  19. Dim solarCorrection
  20. Dim lunarCorrection
  21. Dim paschalFullMoon
  22. Dim dominicalNumber
  23. Dim difference
  24. Dim dayEaster
  25.  
  26. goldenNumber = (someYear Mod 19) + 1
  27.  
  28. if someYear <= 1752 then
  29. ' Julian calendar
  30. dominicalNumber = (someYear + (someYear / 4) + 5) Mod 7
  31. paschalFullMoon = (3 - (11 * goldenNumber) - 7) Mod 30
  32. else
  33. ' Gregorian calendar
  34. dominicalNumber = (someYear + (someYear / 4) - (someYear / 100) + (someYear / 400)) Mod 7
  35. solarCorrection = (someYear - 1600) / 100 - (someYear - 1600) / 400
  36. lunarCorrection = (((someYear - 1400) / 100) * 8) / 25
  37. paschalFullMoon = (3 - 11 * goldenNumber + solarCorrection - lunarCorrection) Mod 30
  38. end if
  39.  
  40. do until dominicalNumber > 0
  41. dominicalNumber = dominicalNumber + 7
  42. loop
  43.  
  44. do until paschalFullMoon > 0
  45. paschalFullMoon = paschalFullMoon + 30
  46. loop
  47.  
  48. if paschalFullMoon = 29 or (paschalFullMoon = 28 and goldenNumber > 11) then
  49. paschalFullMoon = paschalFullMoon - 1
  50. end if
  51.  
  52. difference = (4 - paschalFullMoon - dominicalNumber) Mod 7
  53.  
  54. if difference < 0 then
  55. difference = difference + 7
  56. end if
  57.  
  58. dayEaster = paschalFullMoon + difference + 1
  59.  
  60. if dayEaster < 11 then
  61. ' Easter occurs in March.
  62. dateEaster = DateSerial(someYear, 3, dayEaster + 21)
  63. else
  64. ' Easter occurs in April.
  65. dateEaster = DateSerial(someYear, 4, dayEaster - 10)
  66. end if
  67. end function
  68.  
  69. ' Determine the date of Good Friday for a given year.
  70. ' Requires dateEaster()
  71. function dateGoodFriday(someYear)
  72. dateGoodFriday = DateAdd("d", -2, dateEaster(someYear))
  73. end function
  74.  
  75. ' Determine the date of Palm Sunday for a given year.
  76. ' Requires dateEaster()
  77. function datePalmSunday(someYear)
  78. datePalmSunday = DateAdd("d", -7, dateEaster(someYear))
  79. end function
  80.  
  81. ' Determines the date of Ash Wednesday for a given year.
  82. ' Requires dateEaster()
  83. function dateAshWednesday(someYear)
  84. dateAshWednesday = DateAdd("d", -46, dateEaster(someYear))
  85. end function
  86.  
  87. ' Deteremines the date of Ascension Day for a given year.
  88. ' Requires dateEaster()
  89. function dateAscensionDay(someYear)
  90. dateAscensionDay = DateAdd("d", 39, dateEaster(someYear))
  91. end function
  92.  
  93. ' Determines the date of Pentecost for a given year.
  94. ' Requires dateEaster()
  95. function datePentecost(someYear)
  96. datePentecost = DateAdd("d", 49, dateEaster(someYear))
  97. end function
  98.  
  99. ' Unit tests
  100. ' Dim testYear
  101. ' testYear = 2008
  102. ' Response.Write "Ash Wednesday: " & dateAshWednesday(testYear) & "<br>"
  103. ' Response.Write "Palm Sunday: " & datePalmSunday(testYear) & "<br>"
  104. ' Response.Write "Good Friday: " & dateGoodFriday(testYear) & "<br>"
  105. ' Response.Write "Easter: " & dateEaster(testYear) & "<br>"
  106. ' Response.Write "Ascension Day: " & dateAscensionDay(testYear) & "<br>"
  107. ' Response.Write "Pentecost: " & datePentecost(testYear) & "<br>"
  108. %>

Report this snippet  

You need to login to post a comment.