1module Data.Time.Calendar.Easter
2    (
3    sundayAfter,
4    orthodoxPaschalMoon,orthodoxEaster,
5    gregorianPaschalMoon,gregorianEaster
6    ) where
7
8-- formulae from Reingold & Dershowitz, _Calendrical Calculations_, ch. 8.
9
10import Data.Time.Calendar
11import Data.Time.Calendar.Julian
12
13-- | The next Sunday strictly after a given day.
14sundayAfter :: Day -> Day
15sundayAfter day = addDays (7 - (mod (toModifiedJulianDay day + 3) 7)) day
16
17-- | Given a year, find the Paschal full moon according to Orthodox Christian tradition
18orthodoxPaschalMoon :: Integer -> Day
19orthodoxPaschalMoon year  = addDays (- shiftedEpact) (fromJulian jyear 4 19) where
20    shiftedEpact = mod (14 + 11 * (mod year 19)) 30
21    jyear = if year > 0 then year else year - 1
22
23-- | Given a year, find Easter according to Orthodox Christian tradition
24orthodoxEaster :: Integer -> Day
25orthodoxEaster = sundayAfter . orthodoxPaschalMoon
26
27-- | Given a year, find the Paschal full moon according to the Gregorian method
28gregorianPaschalMoon :: Integer -> Day
29gregorianPaschalMoon year  = addDays (- adjustedEpact) (fromGregorian year 4 19) where
30    century = (div year 100) + 1
31    shiftedEpact = mod (14 + 11 * (mod year 19) - (div (3 * century) 4) + (div (5 + 8 * century) 25)) 30
32    adjustedEpact = if shiftedEpact == 0 || ((shiftedEpact == 1) && (mod year 19 < 10)) then shiftedEpact + 1 else shiftedEpact
33
34-- | Given a year, find Easter according to the Gregorian method
35gregorianEaster :: Integer -> Day
36gregorianEaster = sundayAfter . gregorianPaschalMoon
37