summaryrefslogtreecommitdiff
path: root/Utility/HumanTime.hs
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2024-03-19 19:47:48 +0800
committerSean Whitton <spwhitton@spwhitton.name>2024-03-19 19:47:48 +0800
commit4b47032686c52de5bf2324c1b1d4151c5fd6c41b (patch)
tree85098e25c0a4ad383f267fd59d591346d5e09a17 /Utility/HumanTime.hs
parent34f99f9355c275917ff91539bbdac60a56ad7e17 (diff)
parent4993eab4a4507d52037ff74c67f6ca04d2401b5e (diff)
downloadgit-repair-4b47032686c52de5bf2324c1b1d4151c5fd6c41b.tar.gz
Merge tag '1.20230814'
tagging package git-repair version 1.20230814
Diffstat (limited to 'Utility/HumanTime.hs')
-rw-r--r--Utility/HumanTime.hs10
1 files changed, 6 insertions, 4 deletions
diff --git a/Utility/HumanTime.hs b/Utility/HumanTime.hs
index 51338b3..5178531 100644
--- a/Utility/HumanTime.hs
+++ b/Utility/HumanTime.hs
@@ -44,8 +44,10 @@ daysToDuration :: Integer -> Duration
daysToDuration i = Duration $ i * dsecs
{- Parses a human-input time duration, of the form "5h", "1m", "5h1m", etc -}
-parseDuration :: MonadFail m => String -> m Duration
-parseDuration = maybe parsefail (return . Duration) . go 0
+parseDuration :: String -> Either String Duration
+parseDuration d
+ | null d = parsefail
+ | otherwise = maybe parsefail (Right . Duration) $ go 0 d
where
go n [] = return n
go n s = do
@@ -55,7 +57,7 @@ parseDuration = maybe parsefail (return . 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\""
+ parsefail = Left $ "failed to parse duration \"" ++ d ++ "\" (expected eg \"5m\" or \"1h5m\")"
fromDuration :: Duration -> String
fromDuration Duration { durationSeconds = d }
@@ -101,4 +103,4 @@ instance Arbitrary Duration where
arbitrary = Duration <$> nonNegative arbitrary
prop_duration_roundtrips :: Duration -> Bool
-prop_duration_roundtrips d = parseDuration (fromDuration d) == Just d
+prop_duration_roundtrips d = parseDuration (fromDuration d) == Right d