summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-09-25 16:48:24 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-09-25 16:48:24 -0400
commit51d5e6b4c716847dc544fa2d56bbe4567f1bfaf4 (patch)
treea13a562265b76a756c1d18b66cc0a194902a0dfb /Utility
parent067974202e285bc8d0840c2c64e9b84fc52c7c21 (diff)
New --time-limit option, makes long git-annex commands stop after a specified amount of time.
Diffstat (limited to 'Utility')
-rw-r--r--Utility/HumanTime.hs26
1 files changed, 26 insertions, 0 deletions
diff --git a/Utility/HumanTime.hs b/Utility/HumanTime.hs
new file mode 100644
index 000000000..ca631dbb1
--- /dev/null
+++ b/Utility/HumanTime.hs
@@ -0,0 +1,26 @@
+{- Time for humans.
+ -
+ - Copyright 2012 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Utility.HumanTime where
+
+import Utility.PartialPrelude
+
+import Data.Time.Clock.POSIX (POSIXTime)
+
+{- Parses a human-input time duration, of the form "5h" or "1m". -}
+parseDuration :: String -> Maybe POSIXTime
+parseDuration s = do
+ num <- readish s :: Maybe Integer
+ units <- findUnits =<< lastMaybe s
+ return $ fromIntegral num * units
+ where
+ findUnits 's' = Just 1
+ findUnits 'm' = Just 60
+ findUnits 'h' = Just $ 60 * 60
+ findUnits 'd' = Just $ 60 * 60 * 24
+ findUnits 'y' = Just $ 60 * 60 * 24 * 365
+ findUnits _ = Nothing