packages feed

formatting 6.2.0 → 6.2.1

raw patch · 4 files changed

+32/−6 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Formatting.Formatters: bytesDecimal :: (Ord f, Integral a, Fractional f) => Format Builder (f -> Builder) -> Format r (a -> r)

Files

CHANGELOG.md view
@@ -1,3 +1,7 @@+6.2.1++* Added bytesDecimal+ 6.2.0  * Dropped Holey/HoleyT in favour of simpler Format type.
formatting.cabal view
@@ -1,5 +1,5 @@ name:                formatting-version:             6.2.0+version:             6.2.1 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@@ -20,7 +20,7 @@                      Formatting.Time,                      Formatting.Clock,                      Formatting.Internal-  build-depends:     base >= 4 && < 5,+  build-depends:     base >= 4.5 && < 5,                      text-format,                      text >= 0.11.0.8,                      time,
src/Formatting/Formatters.hs view
@@ -51,16 +51,17 @@   prefixBin,   prefixOct,   prefixHex,+  bytesDecimal,   -- * Buildables   build,-  Buildable+  Buildable,   ) where  import           Formatting.Internal  import           Data.Char (chr, ord)-import           Numeric (showIntAtBase) import           Data.Monoid+import           Data.Scientific import qualified Data.Text as S import qualified Data.Text as T import           Data.Text.Buildable (Buildable)@@ -71,7 +72,7 @@ import           Data.Text.Lazy.Builder (Builder) import qualified Data.Text.Lazy.Builder as T import           Data.Text.Lazy.Builder.Scientific-import           Data.Scientific+import           Numeric (showIntAtBase)  -- | Output a lazy text. text :: Format r (Text -> r)@@ -285,3 +286,24 @@   | i >= 0  && i < 10 = chr (ord '0' + i)   | i >= 10 && i < 36 = chr (ord 'a' + i - 10)   | otherwise = error ("intToDigit': Invalid int " ++ show i)++-- | Renders a given byte count using an appropiate decimal binary suffix, e.g. MiB+--+-- >>> sformat (bytes (fixed 2)) 424242+-- "414.30 KiB"+bytesDecimal :: (Ord f,Integral a,Fractional f)+             => Format Builder (f -> Builder) -- ^ formatter for the decimal part+             -> Format r (a -> r)+bytesDecimal d = later go+  where go bs =+          bprint d (fromIntegral (signum bs) * dec) <> " " <> bytesSuffixes !!+          i+          where (dec,i) = getSuffix (abs bs)+        getSuffix n =+          until p+                (\(x,y) -> (x / 1024,y + 1))+                (fromIntegral n,0)+          where p (n',numDivs) =+                  n' < 1024 || numDivs == (length bytesSuffixes - 1)+        bytesSuffixes =+          ["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]
src/Formatting/Time.hs view
@@ -15,7 +15,7 @@ import qualified Data.Text              as T import           Data.Text.Buildable import           Data.Time-#if __GLASGOW_HASKELL__ >= 710+#if MIN_VERSION_time(1,5,0) import           System.Locale hiding (defaultTimeLocale) #else import           System.Locale