hledger-lib-0.22: Core data types, parsers and utilities for the hledger accounting tool.

Safe HaskellNone

Hledger.Data.Amount

Contents

Synopsis

Amount

amount :: AmountSource

The empty simple amount.

nullamt :: AmountSource

The empty simple amount.

missingamt :: AmountSource

A temporary value for parsed transactions which had no amount specified.

at :: Amount -> Amount -> AmountSource

Set an amount's unit price.

(@@) :: Amount -> Amount -> AmountSource

Set an amount's total price.

amountWithCommodity :: Commodity -> Amount -> AmountSource

Convert an amount to the specified commodity, ignoring and discarding any assigned prices and assuming an exchange rate of 1.

arithmetic

costOfAmount :: Amount -> AmountSource

Convert an amount to the commodity of its assigned price, if any. Notes:

  • price amounts must be MixedAmounts with exactly one component Amount (or there will be a runtime error)
  • price amounts should be positive, though this is not currently enforced

divideAmount :: Amount -> Double -> AmountSource

Divide an amount's quantity by a constant.

sumAmounts :: [Amount] -> MixedAmountSource

A more complete amount adding operation.

rendering

showAmount :: Amount -> StringSource

Get the string representation of an amount, based on its commodity's display settings. String representations equivalent to zero are converted to just "0".

showAmountDebug :: Amount -> StringSource

Get a string representation of an amount for debugging, appropriate to the current debug level. 9 shows maximum detail.

showAmountWithoutPrice :: Amount -> StringSource

Get the string representation of an amount, without any @ price.

maxprecision :: IntSource

For rendering: a special precision value which means show all available digits.

maxprecisionwithpoint :: IntSource

For rendering: a special precision value which forces display of a decimal point.

setAmountPrecision :: Int -> Amount -> AmountSource

Set an amount's display precision.

withPrecision :: Amount -> Int -> AmountSource

Set an amount's display precision, flipped.

canonicaliseAmount :: Map Commodity AmountStyle -> Amount -> AmountSource

Canonicalise an amount's display style using the provided commodity style map.

canonicalStyles :: [Amount] -> Map Commodity AmountStyleSource

Given a list of amounts in parse order, build a map from commodities to canonical display styles for amounts in that commodity.

MixedAmount

nullmixedamt :: MixedAmountSource

The empty mixed amount.

amounts :: MixedAmount -> [Amount]Source

Get a mixed amount's component amounts.

normaliseMixedAmountPreservingFirstPrice :: MixedAmount -> MixedAmountSource

Simplify a mixed amount's component amounts: combine amounts with the same commodity, using the first amount's price for subsequent amounts in each commodity (ie, this function alters the amount and is best used as a rendering helper.). Also remove any zero amounts and replace an empty amount list with a single zero amount.

normaliseMixedAmountPreservingPrices :: MixedAmount -> MixedAmountSource

Simplify a mixed amount's component amounts: we can combine amounts with the same commodity and unit price. Also remove any zero or missing amounts and replace an empty amount list with a single zero amount.

arithmetic

costOfMixedAmount :: MixedAmount -> MixedAmountSource

Convert a mixed amount's component amounts to the commodity of their assigned price, if any.

divideMixedAmount :: MixedAmount -> Double -> MixedAmountSource

Divide a mixed amount's quantities by a constant.

isNegativeMixedAmount :: MixedAmount -> Maybe BoolSource

Is this mixed amount negative, if it can be normalised to a single commodity ?

isZeroMixedAmount :: MixedAmount -> BoolSource

Does this mixed amount appear to be zero when displayed with its given precision ?

isReallyZeroMixedAmount :: MixedAmount -> BoolSource

Is this mixed amount really zero ? See isReallyZeroAmount.

isReallyZeroMixedAmountCost :: MixedAmount -> BoolSource

Is this mixed amount really zero, after converting to cost commodities where possible ?

rendering

showMixedAmount :: MixedAmount -> StringSource

Get the string representation of a mixed amount, showing each of its component amounts. NB a mixed amount can have an empty amounts list in which case it shows as "".

showMixedAmountDebug :: MixedAmount -> StringSource

Get an unambiguous string representation of a mixed amount for debugging.

showMixedAmountWithoutPrice :: MixedAmount -> StringSource

Get the string representation of a mixed amount, but without any @ prices.

showMixedAmountWithPrecision :: Int -> MixedAmount -> StringSource

Get the string representation of a mixed amount, showing each of its component amounts with the specified precision, ignoring their commoditys' display precision settings.

setMixedAmountPrecision :: Int -> MixedAmount -> MixedAmountSource

Set the display precision in the amount's commodities.

canonicaliseMixedAmount :: Map Commodity AmountStyle -> MixedAmount -> MixedAmountSource

Canonicalise a mixed amount's display styles using the provided commodity style map.

misc.

ltraceamount :: String -> MixedAmount -> MixedAmountSource

Compact labelled trace of a mixed amount, for debugging.