Skip to content

Commit a584af9

Browse files
committed
toml instances for UTCTime
1 parent e87e7a5 commit a584af9

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

pub/functora/functora.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ common pkg-prelude
124124
, template-haskell
125125
, text
126126
, th-lift-instances
127-
, time
127+
, time >=1.11.1.1
128128
, transformers
129129
, unbounded-delays
130130
, uniplate

pub/functora/src/cfg/Functora/CfgOrphan.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,29 @@ instance Toml.HasItemCodec URI where
6666
$ Toml.Text
6767
. URI.render
6868

69+
instance Toml.HasCodec UTCTime where
70+
hasCodec =
71+
Toml.textBy (from @String @Text . iso8601Show)
72+
$ maybe (Left "Not a UTCTime") pure
73+
. iso8601ParseM
74+
. from @Text @String
75+
76+
instance Toml.HasItemCodec UTCTime where
77+
hasItemCodec =
78+
Left
79+
. Toml.mkAnyValueBiMap
80+
( \src -> do
81+
txt <- Toml.matchText src
82+
maybe
83+
(Left . Toml.MatchError Toml.TText $ Toml.AnyValue src)
84+
pure
85+
. iso8601ParseM
86+
$ from @Text @String txt
87+
)
88+
$ Toml.Text
89+
. from @String @Text
90+
. iso8601Show
91+
6992
instance (Show a, Enum a, Bounded a) => Toml.HasCodec (GenericEnum a) where
7093
hasCodec = Toml.enumBounded
7194

pub/functora/src/prelude/Functora/Prelude.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ import Data.Time.Clock as X
274274
)
275275
import qualified Data.Time.Clock as Clock
276276
import Data.Time.Clock.POSIX as X (posixSecondsToUTCTime)
277+
import Data.Time.Format.ISO8601 as X (iso8601ParseM, iso8601Show)
277278
import Data.Tuple.Extra as X (thd3, uncurry3)
278279
import qualified Data.Typeable as Typeable
279280
import Functora.PreludeOrphan as X ()

0 commit comments

Comments
 (0)