packages feed

human-readable-duration 0.2.0.1 → 0.2.0.2

raw patch · 3 files changed

+63/−52 lines, 3 filesdep ~human-readable-durationPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: human-readable-duration

API changes (from Hackage documentation)

+ Data.Duration: type Seconds = Micro
- Data.Duration: day :: Micro
+ Data.Duration: day :: Seconds
- Data.Duration: getDays :: Micro -> Integer
+ Data.Duration: getDays :: Seconds -> Integer
- Data.Duration: getHours :: Micro -> Integer
+ Data.Duration: getHours :: Seconds -> Integer
- Data.Duration: getMinutes :: Micro -> Integer
+ Data.Duration: getMinutes :: Seconds -> Integer
- Data.Duration: getMs :: Micro -> Integer
+ Data.Duration: getMs :: Seconds -> Integer
- Data.Duration: getSeconds :: Micro -> Integer
+ Data.Duration: getSeconds :: Seconds -> Integer
- Data.Duration: getYears :: Micro -> Integer
+ Data.Duration: getYears :: Seconds -> Integer
- Data.Duration: hour :: Micro
+ Data.Duration: hour :: Seconds
- Data.Duration: humanReadableDuration :: Micro -> String
+ Data.Duration: humanReadableDuration :: Seconds -> String
- Data.Duration: minute :: Micro
+ Data.Duration: minute :: Seconds
- Data.Duration: ms :: Micro
+ Data.Duration: ms :: Seconds
- Data.Duration: oneSecond :: Micro
+ Data.Duration: oneSecond :: Seconds
- Data.Duration: year :: Micro
+ Data.Duration: year :: Seconds

Files

bench/Main.hs view
@@ -7,4 +7,9 @@ main = defaultMain   [ bgroup "to human"     [ bench "small" $ nf humanReadableDuration 0.123456-    , bench "Basic" $ nf humanReadableDuration 987654321.123456 ]]+    , bench "Basic" $ nf humanReadableDuration 987654321.123456]+  , bgroup "from human back to human"+    [ bench "long" $ nf humanReadableDuration+       (10*ms + 21*oneSecond + 42*minute + 3*hour + 222*day + 45*year)+    ]+  ]
human-readable-duration.cabal view
@@ -1,15 +1,12 @@-name:                human-readable-duration-version:             0.2.0.1-synopsis:            Provide duration helper-homepage:            http://github.com/yogsototh/human-readable-duration#readme-license:             BSD3-license-file:        LICENSE-author:              Yann Esposito-maintainer:          yann.esposito@gmail.com-category:            Time-build-type:          Simple--- extra-source-files:-cabal-version:       >=1.10+name: human-readable-duration+version: 0.2.0.2+cabal-version: >=1.10+build-type: Simple+license: BSD3+license-file: LICENSE+maintainer: yann.esposito@gmail.com+homepage: http://github.com/yogsototh/human-readable-duration#readme+synopsis: Provide duration helper description:     This is a minimal Haskell library to display duration.     .@@ -22,35 +19,41 @@     > -- will return 763     > getMs duration     > -- will return 65923323002+category: Time+author: Yann Esposito +source-repository head+    type: git+    location: https://github.com/yogstoth/human-readable-duration+ library-  hs-source-dirs:      src-  exposed-modules:     Data.Duration-                       Data.Duration.Tutorial-  build-depends:       base >= 4.7 && < 5-  default-language:    Haskell2010+    exposed-modules:+        Data.Duration+        Data.Duration.Tutorial+    build-depends:+        base >=4.7 && <5+    default-language: Haskell2010+    hs-source-dirs: src  test-suite human-readable-duration-test-  type:                exitcode-stdio-1.0-  hs-source-dirs:      test-  main-is:             Spec.hs-  build-depends:       base >= 4.7 && < 5-                     , human-readable-duration-                     , doctest >= 0.9.12-                     , time >= 1.5.0.0-  ghc-options:         -O2 -Wall-  default-language:    Haskell2010+    type: exitcode-stdio-1.0+    main-is: Spec.hs+    build-depends:+        base >=4.7 && <5,+        human-readable-duration >=0.2.0.2,+        doctest >=0.9.12,+        time >=1.5.0.0+    default-language: Haskell2010+    hs-source-dirs: test+    ghc-options: -O2 -Wall  benchmark hrd-bench-  type: exitcode-stdio-1.0-  hs-source-dirs: bench-  main-is: Main.hs-  ghc-options: -O2 -Wall -threaded-  default-language: Haskell2010-  build-depends: base >= 4.7 && < 5-               , criterion >= 1.1.0.0-               , human-readable-duration--source-repository head-  type:     git-  location: https://github.com/yogstoth/human-readable-duration+    type: exitcode-stdio-1.0+    main-is: Main.hs+    build-depends:+        base >=4.7 && <5,+        criterion >=1.1.0.0,+        human-readable-duration >=0.2.0.2+    default-language: Haskell2010+    hs-source-dirs: bench+    ghc-options: -O2 -Wall -threaded
src/Data/Duration.hs view
@@ -16,6 +16,7 @@ module Data.Duration     ( humanReadableDuration     , humanReadableDuration'+    , Seconds     -- durations     , ms     , oneSecond@@ -34,6 +35,8 @@  import Data.Fixed (Fixed(..), Micro, div', mod') +type Seconds = Micro+ {- | `humanReadableDuration` take some time in micro-second precision and render a human readable duration.  >>> let duration = 2 * ms + 3 * oneSecond + 2 * minute + 33*day + 2*year@@ -42,7 +45,7 @@ >>> humanReadableDuration duration "2 years 33 days 2 min 3s 2ms" -}-humanReadableDuration :: Micro -> String+humanReadableDuration :: Seconds -> String humanReadableDuration n   | n < oneSecond = let mi = getMs      n in if mi > 0 then show mi ++ "ms" else ""   | n < minute = let s  = getSeconds n in if s  > 0 then show s  ++ "s " ++ humanReadableDuration (n `mod'` oneSecond) else ""@@ -70,7 +73,7 @@ -- 0.001000 -- >>> 1000 * ms -- 1.000000-ms :: Micro+ms :: Seconds ms = MkFixed 1000  -- | one second (@1@)@@ -79,7 +82,7 @@ -- 1000.000000 -- >>> oneSecond -- 1.000000-oneSecond :: Micro+oneSecond :: Seconds oneSecond = 1000 * ms  -- | number of seconds in one minute@@ -88,7 +91,7 @@ -- 60.000000 -- >>> minute / ms -- 60000.000000-minute :: Micro+minute :: Seconds minute = 60 * oneSecond  -- | number of seconds in one hour@@ -97,7 +100,7 @@ -- 60.000000 -- >>> hour / oneSecond -- 3600.000000-hour :: Micro+hour :: Seconds hour = 60 * minute  -- | number of seconds in one day@@ -106,14 +109,14 @@ -- 24.000000 -- >>> day / oneSecond -- 86400.000000-day :: Micro+day :: Seconds day = 24 * hour  -- | number of seconds in one year -- -- >>> year / day -- 365.000000-year :: Micro+year :: Seconds year = 365 * day  --------------------------------------------------------------------------------@@ -125,7 +128,7 @@ -- 1000 -- >>> getMs 1.618033 -- 1618-getMs :: Micro -> Integer+getMs :: Seconds -> Integer getMs n = n `div'` ms  -- | number of seconds given a duration in micro seconds@@ -134,7 +137,7 @@ -- 1 -- >>> getSeconds 1.618033 -- 1-getSeconds :: Micro -> Integer+getSeconds :: Seconds -> Integer getSeconds n = n `div'` oneSecond  -- | number of minutes given a duration in micro seconds@@ -143,7 +146,7 @@ -- 1 -- >>> getMinutes 59 -- 0-getMinutes :: Micro -> Integer+getMinutes :: Seconds -> Integer getMinutes n = n `div'` minute  -- | number of hours given a duration in micro seconds@@ -154,7 +157,7 @@ -- 1 -- >>> getHours (2 * day) -- 48-getHours :: Micro -> Integer+getHours :: Seconds -> Integer getHours n = n `div'` hour  -- | number of days given a duration in micro seconds@@ -163,7 +166,7 @@ -- 10 -- >>> getDays (240 * hour) -- 10-getDays :: Micro -> Integer+getDays :: Seconds -> Integer getDays n = n `div'` day  -- | number of years given a duration in micro seconds@@ -172,5 +175,5 @@ -- 1 -- >>> getYears (740 * day) -- 2-getYears :: Micro -> Integer+getYears :: Seconds -> Integer getYears n = n `div'` year