-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmaya.hs
More file actions
72 lines (49 loc) · 1.43 KB
/
maya.hs
File metadata and controls
72 lines (49 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
module Maya where
import Kins
import Data.Time (Day, diffDays, fromGregorian)
type Date = (Integer, Int, Int)
kinZero = 207 :: Int
yearZero = 2012 :: Integer
zero = fromGregorian yearZero 12 21 :: Day
daysFromZero :: Date -> Integer
daysFromZero (y, m, d) =
diffDays (fromGregorian y m d) zero
isLeapYear :: Integer -> Bool
isLeapYear y =
y `rem` 4 == 0 && (y `rem` 100 /= 0 || y `rem` 400 == 0)
shouldApplyBissestile :: Date -> Bool
shouldApplyBissestile (y, m, d) =
isLeapYear y && isBeforeNullDay
where
isBeforeNullDay
| m == 2 = d <= 28
| otherwise = m < 2
countLeapYears :: Integer -> Integer
countLeapYears y =
div y 4 - div y 100 + div y 400
pastNullDays :: Date -> Integer
pastNullDays (y, _, _) =
countLeapYears y - countLeapYears yearZero
discountNullDays :: Date -> Integer
discountNullDays date =
pastNullDays date + adjust
where
adjust
| shouldApplyBissestile date = -1
| otherwise = 0
daysFromZeroNoNullDays :: Date -> Integer
daysFromZeroNoNullDays date =
daysFromZero date - discountNullDays date
kinIndexByDate :: Date -> Int
kinIndexByDate (y, m, d) =
(+) kinZero . fromIntegral $ daysFromZeroNoNullDays (y, m', d')
where
(m', d')
| m == 2 && d > 28 = (3, 1)
| otherwise = (m, d)
kinByDate :: Date -> Kin
kinByDate date =
findKin $ kinIndexByDate date
harmonicByDates :: [Date] -> Kin
harmonicByDates list =
findKin . sum $ map kinIndexByDate list