(//) = posit infixl 8 // main :: IO () main = do putStrLn $ dateString 2023 2 24 ++ " JDN = " ++ show (jdnGr 2023 2 24) putStrLn $ dateString 2023 2 28 ++ " JDN = " ++ show (jdnGr 2023 2 28) putStrLn $ dateString 2023 3 1 ++ " JDN = " ++ show (jdnGr 2023 3 1) putStrLn $ dateString 2023 3 3 ++ " weekday is " ++ show (weekday 2023 3 3) putStrLn $ show (daysUntilXmas) ++ " days until Xmas" posit h k = if h >= 0 then (div h k) else negate (div (-h) k) jdnGr y m d = (1461 * (y + 4800 + (m - 14)//12))//4 + (367 * (m - 2 - 12 * ((m - 14)//12)))//12 - ((3 * ((y + 4900 + (m - 14)//12)//100))//4) + d - 32075 dateXmas = jdnGr 2023 12 24 daysUntilXmas = dateXmas - (jdnGr 2023 3 3) weekday y m d = let dayNumber = mod (1 + jdnGr y m d) 7 in case dayNumber of 0 -> "Sunday" 1 -> "Monday" 2 -> "Tuesday" 3 -> "Wednesday" 4 -> "Thursday" 5 -> "Friday" 6 -> "Saturday" _ -> "Unknown day" -- Converts the date (year, month, day) to string dateString :: (Show a1, Show a2, Show a3) => a1 -> a2 -> a3 -> String dateString y m d = (show y) ++ "-" ++ (show m) ++ "-" ++ (show d) :: String