From 7293717a0d25681db295f4f97fbaf14a011bc6a5 Mon Sep 17 00:00:00 2001 From: Alex Mason Date: Fri, 2 Sep 2016 16:16:41 +1000 Subject: [PATCH] Rename {render,parse}Time FTime --- servant/src/Servant/API.hs | 2 +- servant/src/Servant/API/Times.hs | 38 ++++++++++++++------------------ 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/servant/src/Servant/API.hs b/servant/src/Servant/API.hs index 1244cb4e..bf0e102f 100644 --- a/servant/src/Servant/API.hs +++ b/servant/src/Servant/API.hs @@ -83,7 +83,7 @@ import Servant.API.ResponseHeaders (AddHeader (addHeader), HList (..), Headers (..), getHeadersHList, getResponse) import Servant.API.Sub ((:>)) -import Servant.API.Times (FTime(..), getFormat, renderTime, parseTime) +import Servant.API.Times (FTime(..), getFormat, renderFTime, parseFTime) import Servant.API.Vault (Vault) import Servant.API.Verbs (PostCreated, Delete, DeleteAccepted, DeleteNoContent, diff --git a/servant/src/Servant/API/Times.hs b/servant/src/Servant/API/Times.hs index c8bdf01c..58e237c8 100644 --- a/servant/src/Servant/API/Times.hs +++ b/servant/src/Servant/API/Times.hs @@ -11,8 +11,8 @@ module Servant.API.Times ( FTime(..) , toFormatProxy , getFormat - , renderTime - , parseTime + , renderFTime + , parseFTime , ISO8601Date , ISO8601DateTime , ISO8601DateTimeZ @@ -49,7 +49,7 @@ newtype FTime (format :: Symbol) t = FTime {getFTime :: t} deriving (Typeable, Eq, Ord) instance (KnownSymbol format, T.FormatTime t) => Show (FTime format t) where - showsPrec i t = showParen (i > 1) (renderTime t ++) + showsPrec i t = showParen (i > 1) (renderFTime t ++) instance (KnownSymbol format, T.ParseTime t) => Read (FTime format t) where readsPrec i str = res where @@ -61,15 +61,15 @@ instance (KnownSymbol format, T.ParseTime t) => Read (FTime format t) where instance (KnownSymbol format, T.FormatTime t) => ToHttpApiData (FTime format t) where - toUrlPiece = toUrlPiece . renderTime - toHeader = toHeader . renderTime - toQueryParam = toQueryParam . renderTime + toUrlPiece = toUrlPiece . renderFTime + toHeader = toHeader . renderFTime + toQueryParam = toQueryParam . renderFTime instance (KnownSymbol format, T.ParseTime t) => FromHttpApiData (FTime format t) where - parseUrlPiece = parseUrlPiece >=> parseTime - parseHeader = parseHeader >=> parseTime - parseQueryParam = parseQueryParam >=> parseTime + parseUrlPiece = parseUrlPiece >=> parseFTime + parseHeader = parseHeader >=> parseFTime + parseQueryParam = parseQueryParam >=> parseFTime toFormatProxy :: FTime format t -> Proxy format @@ -78,19 +78,15 @@ toFormatProxy _ = Proxy getFormat :: KnownSymbol format => FTime format t -> String getFormat t = symbolVal (toFormatProxy t) -renderTime :: (KnownSymbol format, T.FormatTime t) => FTime format t -> String -renderTime tt@(FTime t) = T.formatTime T.defaultTimeLocale (getFormat tt) t +renderFTime :: (KnownSymbol format, T.FormatTime t) => FTime format t -> String +renderFTime tt@(FTime t) = T.formatTime T.defaultTimeLocale (getFormat tt) t -parseTime :: (KnownSymbol format, T.ParseTime t) => String -> Either Text (FTime format t) -parseTime str = res - where -#if !MIN_VERSION_time(1,5,0) - res = case T.parseTime T.defaultTimeLocale fmt str of -#else - res = case T.parseTimeM False T.defaultTimeLocale fmt str of -#endif - Nothing -> Left . pack $ "Could not parse time string \"" ++ str ++ "\" with format \"" ++ fmt ++ "\"" - Just t -> Right (FTime t) +parseFTime :: (KnownSymbol format, T.ParseTime t) => String -> Either Text (FTime format t) +parseFTime str = res where + res = case ptime T.defaultTimeLocale fmt str of + Nothing -> Left . pack $ "Could not parse time string \"" + ++ str ++ "\" with format \"" ++ fmt ++ "\"" + Just t -> Right (FTime t) fmt = getFormat (toFTimeTy res)