git.iko.soy/typeable/extra-time
on master help sign in
28 lines 823 B history raw
1{-# OPTIONS -Wno-orphans #-}
2{-# LANGUAGE DeriveLift #-}
4module Holidays.EDay (EDay, eDayToDay) where
6import Data.ByteString.Char8
7import Data.Csv
8import Data.Time
9import Data.Time.Calendar.OrdinalDate
10import qualified Data.Vector as V
11import Language.Haskell.TH.Lift
13data EDay = EDay {edYear :: Integer, edDay :: Int}
14 deriving stock (Eq,Ord,Show,Lift)
16eDayToDay :: EDay -> Day
17eDayToDay (EDay y d) = fromOrdinalDate y d
19instance FromField EDay where
20 parseField f = mkEDay <$> parseTimeM False defaultTimeLocale (iso8601DateFormat Nothing) (unpack f)
21 where mkEDay d = let (theYear,theDay) = toOrdinalDate d in EDay theYear theDay
23instance FromRecord EDay where
24 parseRecord v
25 | n == 1 = unsafeIndex v 0
26 | otherwise = fail "Expected single field for a day"
27 where
28 n = V.length v