summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2005-10-28 07:20:34 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 02:41:20 -0400
commit4f1636dbb21da7886116e92e0bc2d3587b38f687 (patch)
tree1b0d7310c1554ef143702a70ed23c737c1026ceb
parent162313d60a3384abdf53a95675e3dc9ad21c95b1 (diff)
downloadfork-ledger-4f1636dbb21da7886116e92e0bc2d3587b38f687.tar.gz
fork-ledger-4f1636dbb21da7886116e92e0bc2d3587b38f687.tar.bz2
fork-ledger-4f1636dbb21da7886116e92e0bc2d3587b38f687.zip
Added a `terminus' global, which if set marks the "current time" as
seen by the value expression logic. This has the effect of changing valexprs that test against the current time, such as for calculating the market value of commodities.
-rw-r--r--config.cc5
-rw-r--r--valexpr.cc8
-rw-r--r--valexpr.h2
3 files changed, 12 insertions, 3 deletions
diff --git a/config.cc b/config.cc
index a7afd152..d77472e5 100644
--- a/config.cc
+++ b/config.cc
@@ -3,6 +3,7 @@
#include "option.h"
#include "datetime.h"
#include "quotes.h"
+#include "valexpr.h"
#include "walk.h"
#ifdef USE_BOOST_PYTHON
#include "py_eval.h"
@@ -647,6 +648,8 @@ OPT_BEGIN(end, "e:") {
config.predicate += "d<[";
config.predicate += buf;
config.predicate += "]";
+
+ terminus = interval.end;
} OPT_END(end);
OPT_BEGIN(current, "c") {
@@ -811,6 +814,8 @@ OPT_BEGIN(period, "p:") {
config.predicate += "d<[";
config.predicate += buf;
config.predicate += "]";
+
+ terminus = interval.end;
}
} OPT_END(period);
diff --git a/valexpr.cc b/valexpr.cc
index e65ecb26..78f481a6 100644
--- a/valexpr.cc
+++ b/valexpr.cc
@@ -13,6 +13,8 @@ namespace ledger {
std::auto_ptr<value_expr_t> amount_expr;
std::auto_ptr<value_expr_t> total_expr;
+std::time_t terminus = now;
+
void value_expr_t::compute(value_t& result, const details_t& details) const
{
switch (kind) {
@@ -112,7 +114,7 @@ void value_expr_t::compute(value_t& result, const details_t& details) const
else if (details.entry)
result = long(details.entry->date());
else
- result = long(now);
+ result = long(terminus);
break;
case CLEARED:
if (details.xact)
@@ -286,7 +288,7 @@ void value_expr_t::compute(value_t& result, const details_t& details) const
assert(left);
left->compute(result, details);
- std::time_t moment = now;
+ std::time_t moment = terminus;
if (right) {
switch (right->kind) {
case DATE:
@@ -453,7 +455,7 @@ value_expr_t * parse_value_term(std::istream& in)
// Basic terms
case 'm':
node.reset(new value_expr_t(value_expr_t::CONSTANT_T));
- node->constant_t = now;
+ node->constant_t = terminus;
break;
case 'a': node.reset(new value_expr_t(value_expr_t::AMOUNT)); break;
diff --git a/valexpr.h b/valexpr.h
index bae9bbab..2c31b4ca 100644
--- a/valexpr.h
+++ b/valexpr.h
@@ -127,6 +127,8 @@ struct value_expr_t
extern std::auto_ptr<value_expr_t> amount_expr;
extern std::auto_ptr<value_expr_t> total_expr;
+extern std::time_t terminus;
+
inline void compute_amount(value_t& result, const details_t& details) {
if (amount_expr.get())
amount_expr->compute(result, details);