Created
May 21, 2013 14:43
-
-
Save nida-001/5620349 to your computer and use it in GitHub Desktop.
Zellar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified System.Time as T | |
type Year = Int | |
type Month = Int | |
type Day = Int | |
-- Ex. $> h 2013 5 21 | |
-- $> Tuesday | |
h :: Year -> Month -> Day -> T.Day | |
h year 1 day = h year 13 day | |
h year 2 day = h year 13 day | |
h year month day = f where | |
f = hToDay $ g `mod` 7 | |
g = day + i + bigy + j + ganma year | |
i = floor $ realToFrac (26 * (month + 1)) / 10 | |
j = floor $ realToFrac bigy / 4 | |
bigy = year `mod` 100 | |
ganma :: Year -> Int | |
ganma = f where | |
f year | |
| year >= 1582 = 5 * bigc + g -- Gregorian | |
| 4 <= year && year < 1582 = 6 * bigc + 5 -- Julian | |
| otherwise = error "ganma" | |
where | |
g = floor $ realToFrac bigc / 4 | |
bigc = floor $ realToFrac year / 100 | |
hToDay :: Int -> T.Day | |
hToDay = f where | |
f 1 = T.Sunday | |
f 2 = T.Monday | |
f 3 = T.Tuesday | |
f 4 = T.Wednesday | |
f 5 = T.Thursday | |
f 6 = T.Friday | |
f 0 = T.Saturday |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment