Merge pull request #5 from typeable/ville/add-opm-holidays

This commit is contained in:
Ville Tirronen 2023-04-12 14:22:03 +03:00 committed by GitHub
commit 1550439fda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

28
src/Holidays/EDay.hs Normal file
View File

@ -0,0 +1,28 @@
{-# OPTIONS -Wno-orphans #-}
{-# LANGUAGE DeriveLift #-}
module Holidays.EDay (EDay, eDayToDay) where
import Data.ByteString.Char8
import Data.Csv
import Data.Time
import Data.Time.Calendar.OrdinalDate
import Data.Vector qualified as V
import Language.Haskell.TH.Lift
data EDay = EDay {edYear :: Integer, edDay :: Int}
deriving stock (Eq,Ord,Show,Lift)
eDayToDay :: EDay -> Day
eDayToDay (EDay y d) = fromOrdinalDate y d
instance FromField EDay where
parseField f = mkEDay <$> parseTimeM False defaultTimeLocale (iso8601DateFormat Nothing) (unpack f)
where mkEDay d = let (theYear,theDay) = toOrdinalDate d in EDay theYear theDay
instance FromRecord EDay where
parseRecord v
| n == 1 = unsafeIndex v 0
| otherwise = fail "Expected single field for a day"
where
n = V.length v