summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-01-23 15:09:43 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-01-23 15:09:43 -0400
commitc860d9e9716510d257a6f348e1740ff1a4fa3a56 (patch)
tree9342e115f644e7711b40be5b2655ce715b856cda /Utility
parentc071d676dce87ae6092100f6cde56faa6a462916 (diff)
add webapp UI to manage unused files
Diffstat (limited to 'Utility')
-rw-r--r--Utility/HumanTime.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/Utility/HumanTime.hs b/Utility/HumanTime.hs
index 644e6fbab..297b2bd97 100644
--- a/Utility/HumanTime.hs
+++ b/Utility/HumanTime.hs
@@ -7,7 +7,10 @@
module Utility.HumanTime (
Duration(..),
+ durationSince,
durationToPOSIXTime,
+ durationToDays,
+ daysToDuration,
parseDuration,
fromDuration,
prop_duration_roundtrips
@@ -17,6 +20,7 @@ import Utility.PartialPrelude
import Utility.Applicative
import Utility.QuickCheck
+import Data.Time.Clock
import Data.Time.Clock.POSIX (POSIXTime)
import Data.Char
import Control.Applicative
@@ -25,9 +29,20 @@ import qualified Data.Map as M
newtype Duration = Duration { durationSeconds :: Integer }
deriving (Eq, Ord, Read, Show)
+durationSince :: UTCTime -> IO Duration
+durationSince pasttime = do
+ now <- getCurrentTime
+ return $ Duration $ round $ diffUTCTime now pasttime
+
durationToPOSIXTime :: Duration -> POSIXTime
durationToPOSIXTime = fromIntegral . durationSeconds
+durationToDays :: Duration -> Integer
+durationToDays d = durationSeconds d `div` dsecs
+
+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