packages feed

byteunits 0.3.0.2 → 0.4.0

raw patch · 2 files changed

+30/−4 lines, 2 filesdep ~basedep ~safePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base, safe

API changes (from Hackage documentation)

+ Data.ByteUnits: instance GHC.Classes.Ord Data.ByteUnits.ByteValue

Files

byteunits.cabal view
@@ -1,5 +1,5 @@ name:                byteunits-version:             0.3.0.2+version:             0.4.0 description:         Human friendly conversion between byte units (KB, MB, GB...)... synopsis:            Human friendly conversion between byte units (KB, MB, GB...) license:             BSD3@@ -18,8 +18,8 @@   hs-source-dirs: src   default-language: Haskell2010   exposed-modules: Data.ByteUnits-  build-depends:       base >=4.9 && <4.10-                       , safe == 0.3.15+  build-depends:       base >=4.5 && <5+                       , safe   default-language:    Haskell2010  Test-Suite testing-example
src/Data/ByteUnits.hs view
@@ -1,12 +1,32 @@+-- | Here is a quick example:+--+--  > ByteValue (1024 * 1024 * 3)+--  > -- the above will evaluate to: ByteValue 3145728.0 Bytes+--+--  > getShortHand . getAppropriateUnits $ ByteValue (1024 * 1024 * 3) Bytes+--  > -- the above will evaluate to: "3.00 MB"+ module Data.ByteUnits where -import Safe+import Safe (lastMay) import Numeric + data ByteUnit = Bytes | KiloBytes | MegaBytes | GigaBytes | TeraBytes | PetaBytes | ExaBytes deriving (Show, Eq)  data ByteValue = ByteValue Float ByteUnit deriving (Show, Eq) ++-- | Also allows comparing sizes, but because it uses float - it might not be 100% accurate+--+-- >>> ByteValue 1024 MegaBytes == ByteValue 1 GigaBytes+-- False+--+-- >>> ByteValue 1023 MegaBytes < ByteValue 1 GigaBytes+-- True+instance Ord ByteValue where+  compare a b = compare (getBytes a) (getBytes b)+ -- | Gets the value of bytes from a ByteValue type -- getBytes :: ByteValue -> Float@@ -21,6 +41,8 @@  -- | Converts the ByteValue to an ByteValue with the specified ByteUnit --+-- >>> convertByteUnit (ByteValue 500 GigaBytes) MegaBytes+-- ByteValue 512000.0 MegaBytes convertByteUnit :: ByteValue -> ByteUnit -> ByteValue convertByteUnit bv bu = case bu of   Bytes -> ByteValue bytes Bytes@@ -49,6 +71,10 @@     Just (bv') -> bv'     Nothing -> bv +-- | Converts to a short string representation +--+-- >>> getShortHand $ ByteValue 100 MegaBytes+-- "100.00 MB" getShortHand :: ByteValue -> String getShortHand (ByteValue v bu) = (showFFloat (Just 2) v) (" " ++buShort) where   buShort = case bu of