git.iko.soy/typeable/extra-time
on master help sign in
Missing file
commita35439332f5a386edec88f46d1476a035096f456 authorVille Tirronen <ville@typeable.io> dateWed 12 Apr 2023, 13:46 (4 years ago) parent4d32a63
1 file changed+28
src/Holidays/EDay.hs+28
src/Holidays/EDay.hsnew file+28
@@ -0,0 +1,28 @@
1+{-# OPTIONS -Wno-orphans #-}
2+{-# LANGUAGE DeriveLift #-}
3+
4+module Holidays.EDay (EDay, eDayToDay) where
5+
6+import Data.ByteString.Char8
7+import Data.Csv
8+import Data.Time
9+import Data.Time.Calendar.OrdinalDate
10+import Data.Vector qualified as V
11+import Language.Haskell.TH.Lift
12+
13+data EDay = EDay {edYear :: Integer, edDay :: Int}
14+ deriving stock (Eq,Ord,Show,Lift)
15+
16+eDayToDay :: EDay -> Day
17+eDayToDay (EDay y d) = fromOrdinalDate y d
18+
19+instance 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
22+
23+instance 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