From a73a4fca93d715c91c0a58fd1dde7af26e040d8d Mon Sep 17 00:00:00 2001 From: Alex Mason Date: Mon, 11 Jan 2016 16:45:34 +1100 Subject: [PATCH] Fix API changes in `time` package between 7.8/7.10 --- servant-server/servant-server.cabal | 2 +- servant/servant.cabal | 6 +++++- servant/src/Servant/API/Times.hs | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/servant-server/servant-server.cabal b/servant-server/servant-server.cabal index d9270546..b572635d 100644 --- a/servant-server/servant-server.cabal +++ b/servant-server/servant-server.cabal @@ -65,7 +65,7 @@ library , wai >= 3.0 && < 3.1 , wai-app-static >= 3.0 && < 3.2 , warp >= 3.0 && < 3.2 - , time >= 1.5 && < 1.6 + , time >= 1.4 && < 1.6 hs-source-dirs: src default-language: Haskell2010 diff --git a/servant/servant.cabal b/servant/servant.cabal index c3e6595d..263ac232 100644 --- a/servant/servant.cabal +++ b/servant/servant.cabal @@ -59,7 +59,11 @@ library , string-conversions >= 0.3 && < 0.5 , network-uri >= 2.6 , vault >= 0.3 && <0.4 - , time >= 1.5 && < 1.6 + if impl(ghc < 7.10) + build-depends: old-locale >= 1.0 && < 1.1 + , time >= 1.4 && < 1.5 + else + build-depends: time >= 1.5 && < 1.6 hs-source-dirs: src default-language: Haskell2010 other-extensions: CPP diff --git a/servant/src/Servant/API/Times.hs b/servant/src/Servant/API/Times.hs index 64ebe14b..96523bfc 100644 --- a/servant/src/Servant/API/Times.hs +++ b/servant/src/Servant/API/Times.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE PolyKinds #-} @@ -18,6 +19,9 @@ import Data.Typeable (Typeable) import GHC.TypeLits -- (Symbol) import Web.HttpApiData import qualified Data.Time.Format as T +#if !MIN_VERSION_time(1,5,0) +import System.Locale as T +#endif import Data.Text (pack, Text) import Data.Proxy import Control.Monad ((>=>)) @@ -40,7 +44,11 @@ instance (KnownSymbol format, T.ParseTime t) => Read (FTime format t) where where res = fmap (first FTime) (readParen (i > 1) +#if !MIN_VERSION_time(1,5,0) + (T.readsTime T.defaultTimeLocale fmt) +#else (T.readSTime False T.defaultTimeLocale fmt) +#endif str ) @@ -75,7 +83,11 @@ renderTime 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)