Rename {render,parse}Time FTime
This commit is contained in:
parent
518a2715be
commit
7293717a0d
2 changed files with 18 additions and 22 deletions
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue