hledger/Ledger/Commodity.hs

41 lines
1.4 KiB
Haskell
Raw Normal View History

{-|
2008-10-15 06:11:30 +04:00
A 'Commodity' is a symbol representing a currency or some other kind of
2008-10-18 23:30:07 +04:00
thing we are tracking, and some display preferences that tell how to
display 'Amount's of the commodity - is the symbol on the left or right,
are thousands separated by comma, significant decimal places and so on.
-}
module Ledger.Commodity
where
import qualified Data.Map as Map
import Ledger.Utils
import Ledger.Types
2008-10-15 10:00:10 +04:00
-- convenient amount and commodity constructors, for tests etc.
2008-10-18 23:30:07 +04:00
unknown = Commodity {symbol="", side=L,spaced=False,comma=False,precision=0}
dollar = Commodity {symbol="$", side=L,spaced=False,comma=False,precision=2}
euro = Commodity {symbol="EUR",side=L,spaced=False,comma=False,precision=2}
2008-10-18 23:30:07 +04:00
pound = Commodity {symbol="£", side=L,spaced=False,comma=False,precision=2}
hour = Commodity {symbol="h", side=R,spaced=False,comma=False,precision=1}
dollars n = Amount dollar n Nothing
euros n = Amount euro n Nothing
pounds n = Amount pound n Nothing
hours n = Amount hour n Nothing
defaultcommodities = [dollar, euro, pound, hour, unknown]
2008-10-18 23:30:07 +04:00
-- | Look up one of the hard-coded default commodities. For use in tests.
comm :: String -> Commodity
2008-10-18 23:30:07 +04:00
comm sym = fromMaybe
(error "commodity lookup failed")
$ find (\(Commodity{symbol=s}) -> s==sym) defaultcommodities
2008-10-18 23:30:07 +04:00
-- | Find the conversion rate between two commodities. Currently returns 1.
conversionRate :: Commodity -> Commodity -> Double
conversionRate oldc newc = 1