formatting 6.0.0 → 6.1.0
raw patch · 2 files changed
+43/−2 lines, 2 filesdep +clockPVP ok
version bump matches the API change (PVP)
Dependencies added: clock
API changes (from Hackage documentation)
+ Formatting.Clock: timeSpecs :: Format r (TimeSpec -> TimeSpec -> r)
Files
- formatting.cabal +4/−2
- src/Formatting/Clock.hs +39/−0
formatting.cabal view
@@ -1,5 +1,5 @@ name: formatting-version: 6.0.0+version: 6.1.0 synopsis: Combinator-based type-safe formatting (like printf() or FORMAT) description: Combinator-based type-safe formatting (like printf() or FORMAT), modelled from the HoleyMonoids package. license: BSD3@@ -19,13 +19,15 @@ Formatting.ShortFormatters, Formatting.Examples, Formatting.Time,+ Formatting.Clock, Formatting.Internal build-depends: base >= 4 && < 5, text-format, text >= 0.11.0.8, time, old-locale,- scientific >= 0.3.0.0+ scientific >= 0.3.0.0,+ clock >= 0.4 hs-source-dirs: src ghc-options: -O2
+ src/Formatting/Clock.hs view
@@ -0,0 +1,39 @@+{-# LANGUAGE PatternGuards #-}+{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_GHC -fno-warn-type-defaults #-}++-- | Formatters for high-res, real-time and timer clock values from "System.Clock".++module Formatting.Clock where++import Formatting+import System.Clock++-- | Format the duration from start to end (args passed in that order).+--+-- Examples:+--+-- @+-- 4.00 s+-- 500.69 ms+-- 1.20 ms+-- 19.38 µs+-- @+timeSpecs :: Format r (TimeSpec -> TimeSpec -> r)+timeSpecs = Holey (\g x y -> g (fmt x y))+ where fmt (TimeSpec s1 n1) (TimeSpec s2 n2)+ | Just i <- scale ((10 ^ 9) * 60 * 60 * 24) = bprint (fixed 2 % " d") i+ | Just i <- scale ((10 ^ 9) * 60 * 60) = bprint (fixed 2 % " h") i+ | Just i <- scale ((10 ^ 9) * 60) = bprint (fixed 2 % " m") i+ | Just i <- scale (10 ^ 9) = bprint (fixed 2 % " s") i+ | Just i <- scale (10 ^ 6) = bprint (fixed 2 % " ms") i+ | Just i <- scale (10 ^ 3) = bprint (fixed 2 % " µs") i+ | otherwise = bprint (int % " ns") diff+ where scale :: Integer -> Maybe Double+ scale i = if diff >= i+ then Just (fromIntegral diff / fromIntegral i)+ else Nothing+ diff :: Integer+ diff = a2 - a1+ a1 = (fromIntegral s1 * 10 ^ 9) + fromIntegral n1+ a2 = (fromIntegral s2 * 10 ^ 9) + fromIntegral n2