summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-01-19 17:47:46 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-01-19 17:47:46 -0400
commitdc91fdeff280a85b5157cf0aea56eae0bd1ae209 (patch)
tree13fea72c726aead01fe3daf4c0c728b10a74de7c /src
parent60f9748da1a316943229087860b74ed48f9bc657 (diff)
downloadfork-ledger-dc91fdeff280a85b5157cf0aea56eae0bd1ae209.tar.gz
fork-ledger-dc91fdeff280a85b5157cf0aea56eae0bd1ae209.tar.bz2
fork-ledger-dc91fdeff280a85b5157cf0aea56eae0bd1ae209.zip
Added argument to amount_t::value() for request a market value in terms of a
specific commodity.
Diffstat (limited to 'src')
-rw-r--r--src/amount.cc6
-rw-r--r--src/amount.h13
2 files changed, 11 insertions, 8 deletions
diff --git a/src/amount.cc b/src/amount.cc
index 32dbf856..b03f4490 100644
--- a/src/amount.cc
+++ b/src/amount.cc
@@ -663,11 +663,11 @@ amount_t& amount_t::in_place_unreduce()
return *this;
}
-optional<amount_t> amount_t::value(const optional<datetime_t>& moment) const
+optional<amount_t> amount_t::value(const optional<datetime_t>& moment,
+ const optional<commodity_t&>& in_terms_of) const
{
if (quantity) {
- // jww (2008-09-21): 'none' is not the right argument here.
- optional<price_point_t> point(commodity().find_price(none, moment));
+ optional<price_point_t> point(commodity().find_price(in_terms_of, moment));
if (point)
return (point->price * number()).round();
} else {
diff --git a/src/amount.h b/src/amount.h
index 0667d9c3..12711ce0 100644
--- a/src/amount.h
+++ b/src/amount.h
@@ -354,10 +354,11 @@ public:
* compact form greater than 1.0. That is, 3599s will unreduce to
* 59.98m, while 3601 unreduces to 1h.
*
- * value(optional<datetime_t>) returns the historical value for an
- * amount -- the default moment returns the most recently known
- * price -- based on the price history of its commodity. For
- * example, if the amount were 10 AAPL, and on Apr 10, 2000 each
+ * value(optional<datetime_t>, optional<commodity_t>) returns the
+ * historical value for an amount -- the default moment returns the
+ * most recently known price -- based on the price history for the
+ * given commodity (or determined automatically, if none is provided).
+ * For example, if the amount were 10 AAPL, and on Apr 10, 2000 each
* share of AAPL was worth $10, then call value() for that moment in
* time would yield the amount $100.00.
*
@@ -419,7 +420,9 @@ public:
}
amount_t& in_place_unreduce();
- optional<amount_t> value(const optional<datetime_t>& moment = none) const;
+ optional<amount_t>
+ value(const optional<datetime_t>& moment = none,
+ const optional<commodity_t&>& in_terms_of = none) const;
/**
* Truth tests. An amount may be truth test in several ways: