summaryrefslogtreecommitdiff
path: root/src/filters.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2010-06-13 23:41:50 -0400
committerJohn Wiegley <johnw@newartisans.com>2010-06-13 23:41:50 -0400
commite78af146e810eaaf0a44fd5c5d745efa2bbf9561 (patch)
treef145e19066d0f550ad2c66a223c50ec4f5c99aa7 /src/filters.cc
parent526cbc4c935fa71376a838ed25247e46a2b019dc (diff)
downloadfork-ledger-e78af146e810eaaf0a44fd5c5d745efa2bbf9561.tar.gz
fork-ledger-e78af146e810eaaf0a44fd5c5d745efa2bbf9561.tar.bz2
fork-ledger-e78af146e810eaaf0a44fd5c5d745efa2bbf9561.zip
Corrected bug with forecasting date bounded xacts
Diffstat (limited to 'src/filters.cc')
-rw-r--r--src/filters.cc29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/filters.cc b/src/filters.cc
index 86386f58..2992f512 100644
--- a/src/filters.cc
+++ b/src/filters.cc
@@ -1228,18 +1228,16 @@ void budget_posts::operator()(post_t& post)
void forecast_posts::add_post(const date_interval_t& period, post_t& post)
{
- generate_posts::add_post(period, post);
+ date_interval_t i(period);
+ if (! i.start && ! i.find_period(CURRENT_DATE()))
+ return;
+
+ generate_posts::add_post(i, post);
- // Advance the period's interval until it is at or beyond the current date.
- date_interval_t& i = pending_posts.back().first;
- if (! i.start) {
- if (! i.find_period(CURRENT_DATE()))
- throw_(std::runtime_error, _("Something odd has happened"));
+ // Advance the period's interval until it is at or beyond the current
+ // date.
+ while (*i.start < CURRENT_DATE())
++i;
- } else {
- while (*i.start < CURRENT_DATE())
- ++i;
- }
}
void forecast_posts::flush()
@@ -1281,6 +1279,8 @@ void forecast_posts::flush()
for (pending_posts_list::iterator i = ++pending_posts.begin();
i != pending_posts.end();
i++) {
+ assert((*i).first.start);
+ assert((*least).first.start);
if (*(*i).first.start < *(*least).first.start)
least = i;
}
@@ -1307,7 +1307,6 @@ void forecast_posts::flush()
}
begin = next;
- ++(*least).first;
// `post' refers to the posting defined in the period transaction. We
// make a copy of it within a temporary transaction with the payee
@@ -1337,6 +1336,14 @@ void forecast_posts::flush()
continue;
}
}
+
+ // Increment the 'least', but remove it from pending_posts if it
+ // exceeds its own boundaries.
+ ++(*least).first;
+ if (! (*least).first.start) {
+ pending_posts.erase(least);
+ continue;
+ }
}
item_handler<post_t>::flush();