Fix API changes in time package between 7.8/7.10

This commit is contained in:
Alex Mason 2016-01-11 16:45:34 +11:00
parent 070fe26831
commit a73a4fca93
3 changed files with 18 additions and 2 deletions

View file

@ -65,7 +65,7 @@ library
, wai >= 3.0 && < 3.1 , wai >= 3.0 && < 3.1
, wai-app-static >= 3.0 && < 3.2 , wai-app-static >= 3.0 && < 3.2
, warp >= 3.0 && < 3.2 , warp >= 3.0 && < 3.2
, time >= 1.5 && < 1.6 , time >= 1.4 && < 1.6
hs-source-dirs: src hs-source-dirs: src
default-language: Haskell2010 default-language: Haskell2010

View file

@ -59,7 +59,11 @@ library
, string-conversions >= 0.3 && < 0.5 , string-conversions >= 0.3 && < 0.5
, network-uri >= 2.6 , network-uri >= 2.6
, vault >= 0.3 && <0.4 , 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 hs-source-dirs: src
default-language: Haskell2010 default-language: Haskell2010
other-extensions: CPP other-extensions: CPP

View file

@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-} {-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE PolyKinds #-} {-# LANGUAGE PolyKinds #-}
@ -18,6 +19,9 @@ import Data.Typeable (Typeable)
import GHC.TypeLits -- (Symbol) import GHC.TypeLits -- (Symbol)
import Web.HttpApiData import Web.HttpApiData
import qualified Data.Time.Format as T 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.Text (pack, Text)
import Data.Proxy import Data.Proxy
import Control.Monad ((>=>)) import Control.Monad ((>=>))
@ -40,7 +44,11 @@ instance (KnownSymbol format, T.ParseTime t) => Read (FTime format t) where
where where
res = fmap (first FTime) res = fmap (first FTime)
(readParen (i > 1) (readParen (i > 1)
#if !MIN_VERSION_time(1,5,0)
(T.readsTime T.defaultTimeLocale fmt)
#else
(T.readSTime False T.defaultTimeLocale fmt) (T.readSTime False T.defaultTimeLocale fmt)
#endif
str 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 :: (KnownSymbol format, T.ParseTime t) => String -> Either Text (FTime format t)
parseTime str = res parseTime str = res
where 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 res = case T.parseTimeM False T.defaultTimeLocale fmt str of
#endif
Nothing -> Left . pack $ "Could not parse time string \"" ++ str ++ "\" with format \"" ++ fmt ++ "\"" Nothing -> Left . pack $ "Could not parse time string \"" ++ str ++ "\" with format \"" ++ fmt ++ "\""
Just t -> Right (FTime t) Just t -> Right (FTime t)