2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -0,0 +1,44 @@
import Data.Time (isLeapYear)
import Data.Time.Calendar.MonthDay (monthAndDayToDayOfYear)
import Text.Printf (printf)
type Year = Integer
type Day = Int
type Month = Int
data DDate = DDate Weekday Season Day Year
| StTibsDay Year deriving (Eq, Ord)
data Season = Chaos
| Discord
| Confusion
| Bureaucracy
| TheAftermath
deriving (Show, Enum, Eq, Ord, Bounded)
data Weekday = Sweetmorn
| Boomtime
| Pungenday
| PricklePrickle
| SettingOrange
deriving (Show, Enum, Eq, Ord, Bounded)
instance Show DDate where
show (StTibsDay y) = printf "St. Tib's Day, %d YOLD" y
show (DDate w s d y) = printf "%s, %s %d, %d YOLD" (show w) (show s) d y
fromYMD :: (Year, Month, Day) -> DDate
fromYMD (y, m, d)
| leap && dayOfYear == 59 = StTibsDay yold
| leap && dayOfYear >= 60 = mkDDate $ dayOfYear - 1
| otherwise = mkDDate dayOfYear
where
yold = y + 1166
dayOfYear = monthAndDayToDayOfYear leap m d - 1
leap = isLeapYear y
mkDDate dayOfYear = DDate weekday season dayOfSeason yold
where
weekday = toEnum $ dayOfYear `mod` 5
season = toEnum $ dayOfYear `div` 73
dayOfSeason = 1 + dayOfYear `mod` 73

View file

@ -0,0 +1,11 @@
test = mapM_ display dates
where
display d = putStr (show d ++ " -> ") >> print (fromYMD d)
dates = [(2012,2,28)
,(2012,2,29)
,(2012,3,1)
,(2012,3,14)
,(2012,3,15)
,(2010,9,2)
,(2010,12,31)
,(2011,1,1)]

View file

@ -1,14 +0,0 @@
import Data.List
import Data.Time
import Data.Time.Calendar.MonthDay
seasons = words "Chaos Discord Confusion Bureaucracy The_Aftermath"
discordianDate (y,m,d) = do
let doy = monthAndDayToDayOfYear (isLeapYear y) m d
(season, dday) = divMod doy 73
dos = dday - fromEnum (isLeapYear y && m >2)
dDate
| isLeapYear y && m==2 && d==29 = "St. Tib's Day, " ++ show (y+1166) ++ " YOLD"
| otherwise = seasons!!season ++ " " ++ show dos ++ ", " ++ show (y+1166) ++ " YOLD"
putStrLn dDate