packages feed

currencies 0.1.1.0 → 0.1.1.1

raw patch · 5 files changed

+39/−16 lines, 5 filesnew-uploaderPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

README.md view
@@ -13,10 +13,10 @@ -- "USD 2,342.20"  prettyPrint (Amount EUR 45827.346)--- "UER 45,827.35"+-- "EUR 45,827.35"  prettyPrintWith (defaultConfig { useCurrencySymbol = True }) (Amount USD 2342.2)--- "$ a,342.20"+-- "$ 2,342.20"  prettyPrintWith (defaultConfig { useCurrencySymbol = True }) (Amount EUR 2342.2) -- "€ 2,342.20"@@ -30,6 +30,6 @@ prettyPrint $ convert USD (Amount EUR 23482.34) -- "USD 27,709.16" -compareAmounts  (Amount EUR 1000) (Amount BTC 1)+compareAmounts  (Amount EUR 1000) (Amount BTC 1) -- Compare to Bitcoin -- LT ```
currencies.cabal view
@@ -1,5 +1,5 @@ name:                currencies-version:             0.1.1.0+version:             0.1.1.1 synopsis:            Currencies representation, pretty printing and conversion description:         ISO 4217 Currencies representation, pretty printing and conversion:     .@@ -11,9 +11,9 @@ homepage:            https://github.com/alx741/currencies#readme license:             BSD3 license-file:        LICENSE-author:              Daniel Campoverde [alx741]+author:              Daniel Campoverde maintainer:          alx@sillybytes.net-copyright:           2017 Daniel Campoverde [alx741]+copyright:           2017 Daniel Campoverde category:            Data build-type:          Simple extra-source-files:  README.md
src/Data/Currency/Currencies.hs view
@@ -1,3 +1,5 @@+-- {-# LANGUAGE EmptyDataDecls #-}+ -- | ISO 4217 compliant and other currencies  module Data.Currency.Currencies@@ -45,6 +47,9 @@   | Fictional -- ^ Currencies used in games, movies, novels, and other fictional setups   deriving (Show, Read, Eq) ++-- TODO: Strive to use 'Deriving Empty' with -XEmptyDataDecls in the future if it gets into GHC+-- https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0006-deriving-empty.rst  -- | Brazilian Real data BRL = BRL deriving (Show, Read, Eq)
src/Data/Currency/Pretty.hs view
@@ -36,9 +36,9 @@     , module Data.Currency.Amounts     ) where -import Text.Printf import Data.Currency.Amounts-import Data.Monoid ((<>))+import Data.Monoid           ((<>))+import Text.Printf  -- | Pretty print a monetary amount using 'defaultConfig' prettyPrint :: (Currency c) => Amount c -> String@@ -75,11 +75,15 @@  largeAmountSeparate :: (Currency c) => c -> PrettyConfig -> String -> String largeAmountSeparate currency cnf amount-    | compactFourDigitAmounts cnf = if length integer <= 4 then amount else separated ++ decimal-    | otherwise = separated ++ decimal+    | compactFourDigitAmounts cnf = if length integer <= 4+        then sign mSign unsignedAmount+        else separatedAmount+    | otherwise = separatedAmount     where-        (integer, decimal) = span (/= '.') amount+        (mSign, unsignedAmount) = unSign amount+        (integer, decimal) = span (/= '.') unsignedAmount         separated = reverse $ intersperseN 3 (largeAmountSeparator cnf) $ reverse integer+        separatedAmount = sign mSign $ separated ++ decimal  toDecimalString :: (Currency c) => c -> PrettyConfig -> Double -> String toDecimalString currency cnf amount@@ -93,20 +97,29 @@     | otherwise = (take ++ [s]) ++ intersperseN n s remainder     where (take, remainder) = splitAt n ss +sign :: Maybe Char -> String -> String+sign (Just s) a = s : a+sign Nothing a  = a +unSign :: String -> (Maybe Char, String)+unSign ('-':s) = (Just '-', s)+unSign ('+':s) = (Just '+', s)+unSign s       = (Nothing, s)++ data PrettyConfig = PrettyConfig-    { showDecimals :: Bool+    { showDecimals            :: Bool     -- | Print four digits amounts as     -- /USD 1000,00/ instead of /USD 1,000.00/     , compactFourDigitAmounts :: Bool     -- | Replace the currency ISO code with its symbol to produce     -- /$ 23.50/ instead of /USD 23.50/-    , useCurrencySymbol :: Bool+    , useCurrencySymbol       :: Bool     -- | Use the currency ISO code as suffix to produce     -- /23.50 USD/ instead of /USD 23.50/-    , suffixIsoCode :: Bool-    , largeAmountSeparator :: Char-    , decimalSeparator :: Char+    , suffixIsoCode           :: Bool+    , largeAmountSeparator    :: Char+    , decimalSeparator        :: Char     } deriving (Show)  
test/Data/Currency/PrettySpec.hs view
@@ -13,6 +13,7 @@             prettyPrint (Amount USD 300.251)  `shouldBe` "USD 300.25"             prettyPrint (Amount USD 3.4)  `shouldBe` "USD 3.40"             prettyPrint (Amount EUR 15.589)  `shouldBe` "EUR 15.59"+            prettyPrint (Amount USD (-300.251))  `shouldBe` "USD -300.25"          it "respects currency decimal digits" $ do             prettyPrint (Amount CLP 345.35)  `shouldBe` "CLP 345"@@ -44,19 +45,23 @@         it "uses large amounts separators" $ do             prettyPrint (Amount USD 32323.50)  `shouldBe` "USD 32,323.50"             prettyPrint (Amount EUR 3827115.259)  `shouldBe` "EUR 3,827,115.26"+            prettyPrint (Amount USD (-129553.53))  `shouldBe` "USD -129,553.53"          it "can use a custom large amounts separator" $ do             let config = defaultConfig { largeAmountSeparator = ' ' }             prettyPrintWith config (Amount USD 32323.50)  `shouldBe` "USD 32 323.50"             prettyPrintWith config (Amount EUR 3827115.259)  `shouldBe` "EUR 3 827 115.26"+            prettyPrintWith config (Amount USD (-129553.53))  `shouldBe` "USD -129 553.53"          it "can avoid separating 4 digit amounts" $ do             prettyPrint (Amount USD 2323.50)  `shouldBe` "USD 2323.50"             prettyPrint (Amount EUR 4629.25)  `shouldBe` "EUR 4629.25"             prettyPrint (Amount USD 23875.00)  `shouldBe` "USD 23,875.00"+            prettyPrint (Amount EUR (-629.25))  `shouldBe` "EUR -629.25"          it "can force 4-digit amounts separation" $ do             let config = defaultConfig { compactFourDigitAmounts = False}             prettyPrintWith config (Amount USD 2323.50)  `shouldBe` "USD 2,323.50"             prettyPrintWith config (Amount EUR 4629.25)  `shouldBe` "EUR 4,629.25"             prettyPrintWith config (Amount USD 23875.00)  `shouldBe` "USD 23,875.00"+            prettyPrintWith config (Amount EUR (-629.25))  `shouldBe` "EUR -629.25"