aboutsummaryrefslogtreecommitdiff
path: root/Utility/HumanTime.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-07-08 16:08:26 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-07-08 16:08:26 -0400
commit931f0f7bc6eb1ea6d25dec52e14c584f0cbd4778 (patch)
treeee99f18ac9124f390425693947e927d40cb8f524 /Utility/HumanTime.hs
parent85a2cfa4da5ad3d3d89554ddc142062581574cff (diff)
generalize parseDuration so it can be used in the ReadM monad
Diffstat (limited to 'Utility/HumanTime.hs')
-rw-r--r--Utility/HumanTime.hs6
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 }