diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-07-08 16:08:26 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-07-08 16:08:26 -0400 |
commit | 931f0f7bc6eb1ea6d25dec52e14c584f0cbd4778 (patch) | |
tree | ee99f18ac9124f390425693947e927d40cb8f524 /Utility | |
parent | 85a2cfa4da5ad3d3d89554ddc142062581574cff (diff) |
generalize parseDuration so it can be used in the ReadM monad
Diffstat (limited to 'Utility')
-rw-r--r-- | Utility/HumanTime.hs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/Utility/HumanTime.hs b/Utility/HumanTime.hs index e8fdb7c6e..fe7cf22a9 100644 --- a/Utility/HumanTime.hs +++ b/Utility/HumanTime.hs @@ -17,7 +17,6 @@ module Utility.HumanTime ( ) where import Utility.PartialPrelude -import Utility.Applicative import Utility.QuickCheck import qualified Data.Map as M @@ -45,8 +44,8 @@ daysToDuration :: Integer -> Duration daysToDuration i = Duration $ i * dsecs {- Parses a human-input time duration, of the form "5h", "1m", "5h1m", etc -} -parseDuration :: String -> Maybe Duration -parseDuration = Duration <$$> go 0 +parseDuration :: Monad m => String -> m Duration +parseDuration = maybe parsefail (return . Duration) . go 0 where go n [] = return n go n s = do @@ -56,6 +55,7 @@ parseDuration = Duration <$$> go 0 u <- M.lookup c unitmap go (n + num * u) rest _ -> return $ n + num + parsefail = fail "duration parse error; expected eg \"5m\" or \"1h5m\"" fromDuration :: Duration -> String fromDuration Duration { durationSeconds = d } |