human-readable-duration 0.1.0.0 → 0.1.1.0
raw patch · 2 files changed
+23/−4 lines, 2 filesdep +timePVP ok
version bump matches the API change (PVP)
Dependencies added: time
API changes (from Hackage documentation)
+ Data.Duration: humanReadableDiffTime :: DiffTime -> String
+ Data.Duration: humanReadableNominalDiffTime :: NominalDiffTime -> String
Files
- human-readable-duration.cabal +5/−4
- src/Data/Duration.hs +18/−0
human-readable-duration.cabal view
@@ -1,5 +1,5 @@ name: human-readable-duration-version: 0.1.0.0+version: 0.1.1.0 synopsis: Provide duration helper homepage: http://github.com/yogsototh/human-readable-duration#readme license: BSD3@@ -15,18 +15,19 @@ . > let duration = 2 * ms + 3 * oneSecond + 2 * minute + 33*day + 2*year > humanReadableDuration duration- > -- will return: "2 years 33 days 2 min 3s 32ms"+ > -- will return: "2 years 33 days 2 min 3s 2ms" > getYears duration > -- will return 2 > getDays duration- > -- will return 730+ > -- will return 763 > getMs duration- > -- will return 730+ > -- will return 65923323002 library hs-source-dirs: src exposed-modules: Data.Duration build-depends: base >= 4.7 && < 5+ , time >= 1.0 default-language: Haskell2010 -- test-suite human-readable-duration-test
src/Data/Duration.hs view
@@ -1,5 +1,7 @@ module Data.Duration ( humanReadableDuration+ , humanReadableDiffTime+ , humanReadableNominalDiffTime -- durations , ms , oneSecond@@ -16,6 +18,7 @@ , getYears ) where +import Data.Time.Clock (DiffTime, NominalDiffTime) -- | `humanReadableDuration` take some time in micro-seconds and render a human readable duration. --@@ -30,6 +33,21 @@ | n < day = let h = getHours n in if h > 0 then show h ++ " hours " ++ humanReadableDuration (n `rem` hour) else "" | n < year = let d = getDays n in if d > 0 then show d ++ " days " ++ humanReadableDuration (n `rem` day) else "" | otherwise = let y = getYears n in if y > 0 then show y ++ " years " ++ humanReadableDuration (n `rem` year) else ""++-- | Give a human readable output of a `DiffTime` from the time library.+humanReadableDiffTime :: DiffTime -> String+humanReadableDiffTime = humanReadableDuration+ . round+ . (* (1e6 :: Double))+ . realToFrac++-- | Give a human readable output of a `NominalDiffTime` from the time library.+humanReadableNominalDiffTime :: NominalDiffTime -> String+humanReadableNominalDiffTime = humanReadableDuration+ . round+ . (* (1e6 :: Double))+ . realToFrac+ -------------------------------------------------------------------------------- -- Durations