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