[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36
John Goerzen
jgoerzen at complete.org
Fri Apr 23 15:13:21 UTC 2010
The following commit has been merged in the master branch:
commit 43d9490d2d8349c6477fa5afc35c2b249d2f4652
Author: John Goerzen <jgoerzen at complete.org>
Date: Wed Nov 22 23:33:58 2006 +0100
Added renderSecs and renderTD
diff --git a/MissingH/Time.hs b/MissingH/Time.hs
index 6c36b9a..7151046 100644
--- a/MissingH/Time.hs
+++ b/MissingH/Time.hs
@@ -37,7 +37,8 @@ module MissingH.Time(
timeDiffToSecs,
epoch,
epochToClockTime,
- clockTimeToEpoch
+ clockTimeToEpoch,
+ renderSecs, renderTD
)
where
import System.Time
@@ -116,3 +117,27 @@ System.Posix.Types. The inverse of 'epochToClockTime'.
Fractions of a second are not preserved by this function. -}
clockTimeToEpoch :: Num a => ClockTime -> a
clockTimeToEpoch (TOD sec _) = fromInteger sec
+
+{- | Render a number of seconds as a human-readable amount. Shows the two
+most significant places. For instance:
+
+>renderSecs 121 = "2m1s"
+
+See also 'renderTD' for a function that works on a TimeDiff.
+-}
+renderSecs :: Integer -> String
+renderSecs i = renderTD $ diffClockTimes (TOD i 0) (TOD 0 0)
+
+{- | Like 'renderSecs', but takes a TimeDiff instead of an integer second
+count. -}
+renderTD :: TimeDiff -> String
+renderTD itd =
+ case workinglist of
+ [] -> "0s"
+ _ -> concat . map (\(q, s) -> show q ++ [s]) $ workinglist
+ where td = normalizeTimeDiff itd
+ suffixlist = "yMdhms"
+ quantlist = (\(TimeDiff y mo d h m s _) -> [y, mo, d, h, m, s]) td
+ zippedlist = zip quantlist suffixlist
+ -- Drop all leading elements that are 0, then take at most 2
+ workinglist = take 2 . dropWhile (\(q, _) -> q == 0) $ zippedlist
\ No newline at end of file
--
haskell-testpack
More information about the Pkg-haskell-commits
mailing list