Skip to content

Commit

Permalink
Use Data.Time.Text to provide conversion functions between time val…
Browse files Browse the repository at this point in the history
…ues and text.
  • Loading branch information
jonathanknowles committed Jul 18, 2019
1 parent 257f394 commit 1fac62c
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Expand Up @@ -115,8 +115,8 @@ import Data.Text.Class
)
import Data.Time
( UTCTime )
import Data.Time.Format
( defaultTimeLocale, formatTime, parseTimeM )
import Data.Time.Text
( iso8601BasicUtc, utcTimeFromText, utcTimeToText )
import Fmt
( pretty )
import GHC.Generics
Expand Down Expand Up @@ -255,7 +255,7 @@ instance KnownSymbol name => ToText (Iso8601Range name) where
suffix = timeToText t1 <> "-" <> timeToText t2
timeToText = \case
Nothing -> "*"
Just t -> T.pack $ formatTime defaultTimeLocale basicUtc t
Just t -> utcTimeToText iso8601BasicUtc t

instance KnownSymbol name => FromText (Iso8601Range name) where
fromText t = do
Expand Down Expand Up @@ -286,12 +286,7 @@ instance KnownSymbol name => FromText (Iso8601Range name) where
parseTime :: Text -> Maybe (Maybe UTCTime)
parseTime = \case
"*" -> pure Nothing
timeText -> pure <$>
parseTimeM False defaultTimeLocale basicUtc $ T.unpack timeText

-- | ISO 8601 basic format (UTC).
basicUtc :: String
basicUtc = "%Y%m%dT%H%M%S%QZ"
timeText -> pure <$> utcTimeFromText [iso8601BasicUtc] timeText

instance KnownSymbol name => FromHttpApiData (Iso8601Range (name :: Symbol))
where
Expand Down

0 comments on commit 1fac62c

Please sign in to comment.