summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/filters.cc29
-rw-r--r--test/baseline/opt-forecast-while.test74
-rw-r--r--test/regress/E627C594.test2
3 files changed, 57 insertions, 48 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();
diff --git a/test/baseline/opt-forecast-while.test b/test/baseline/opt-forecast-while.test
index c2563a75..e3f1c57a 100644
--- a/test/baseline/opt-forecast-while.test
+++ b/test/baseline/opt-forecast-while.test
@@ -244,42 +244,42 @@ reg --now=2009/03/21 --forecast-while='total < $3500' books
09-Nov-30 End of November Expenses:Books $110.00 $2880.00
09-Dec-01 December Expenses:Books $120.00 $3000.00
09-Dec-31 End of December Expenses:Books $120.00 $3120.00
-09-May-01 Forecast transaction Expenses:Books $10.00 $3130.00
-09-Jun-01 Forecast transaction Expenses:Books $10.00 $3140.00
-09-Jul-01 Forecast transaction Expenses:Books $10.00 $3150.00
-09-Aug-01 Forecast transaction Expenses:Books $10.00 $3160.00
-09-Sep-01 Forecast transaction Expenses:Books $10.00 $3170.00
-09-Oct-01 Forecast transaction Expenses:Books $10.00 $3180.00
-09-Nov-01 Forecast transaction Expenses:Books $10.00 $3190.00
-09-Dec-01 Forecast transaction Expenses:Books $10.00 $3200.00
-10-Jan-01 Forecast transaction Expenses:Books $10.00 $3210.00
-10-Feb-01 Forecast transaction Expenses:Books $10.00 $3220.00
-10-Mar-01 Forecast transaction Expenses:Books $10.00 $3230.00
-10-Apr-01 Forecast transaction Expenses:Books $10.00 $3240.00
-10-May-01 Forecast transaction Expenses:Books $10.00 $3250.00
-10-Jun-01 Forecast transaction Expenses:Books $10.00 $3260.00
-10-Jul-01 Forecast transaction Expenses:Books $10.00 $3270.00
-10-Aug-01 Forecast transaction Expenses:Books $10.00 $3280.00
-10-Sep-01 Forecast transaction Expenses:Books $10.00 $3290.00
-10-Oct-01 Forecast transaction Expenses:Books $10.00 $3300.00
-10-Nov-01 Forecast transaction Expenses:Books $10.00 $3310.00
-10-Dec-01 Forecast transaction Expenses:Books $10.00 $3320.00
-11-Jan-01 Forecast transaction Expenses:Books $10.00 $3330.00
-11-Feb-01 Forecast transaction Expenses:Books $10.00 $3340.00
-11-Mar-01 Forecast transaction Expenses:Books $10.00 $3350.00
-11-Apr-01 Forecast transaction Expenses:Books $10.00 $3360.00
-11-May-01 Forecast transaction Expenses:Books $10.00 $3370.00
-11-Jun-01 Forecast transaction Expenses:Books $10.00 $3380.00
-11-Jul-01 Forecast transaction Expenses:Books $10.00 $3390.00
-11-Aug-01 Forecast transaction Expenses:Books $10.00 $3400.00
-11-Sep-01 Forecast transaction Expenses:Books $10.00 $3410.00
-11-Oct-01 Forecast transaction Expenses:Books $10.00 $3420.00
-11-Nov-01 Forecast transaction Expenses:Books $10.00 $3430.00
-11-Dec-01 Forecast transaction Expenses:Books $10.00 $3440.00
-12-Jan-01 Forecast transaction Expenses:Books $10.00 $3450.00
-12-Feb-01 Forecast transaction Expenses:Books $10.00 $3460.00
-12-Mar-01 Forecast transaction Expenses:Books $10.00 $3470.00
-12-Apr-01 Forecast transaction Expenses:Books $10.00 $3480.00
-12-May-01 Forecast transaction Expenses:Books $10.00 $3490.00
+09-Apr-01 Forecast transaction Expenses:Books $10.00 $3130.00
+09-May-01 Forecast transaction Expenses:Books $10.00 $3140.00
+09-Jun-01 Forecast transaction Expenses:Books $10.00 $3150.00
+09-Jul-01 Forecast transaction Expenses:Books $10.00 $3160.00
+09-Aug-01 Forecast transaction Expenses:Books $10.00 $3170.00
+09-Sep-01 Forecast transaction Expenses:Books $10.00 $3180.00
+09-Oct-01 Forecast transaction Expenses:Books $10.00 $3190.00
+09-Nov-01 Forecast transaction Expenses:Books $10.00 $3200.00
+09-Dec-01 Forecast transaction Expenses:Books $10.00 $3210.00
+10-Jan-01 Forecast transaction Expenses:Books $10.00 $3220.00
+10-Feb-01 Forecast transaction Expenses:Books $10.00 $3230.00
+10-Mar-01 Forecast transaction Expenses:Books $10.00 $3240.00
+10-Apr-01 Forecast transaction Expenses:Books $10.00 $3250.00
+10-May-01 Forecast transaction Expenses:Books $10.00 $3260.00
+10-Jun-01 Forecast transaction Expenses:Books $10.00 $3270.00
+10-Jul-01 Forecast transaction Expenses:Books $10.00 $3280.00
+10-Aug-01 Forecast transaction Expenses:Books $10.00 $3290.00
+10-Sep-01 Forecast transaction Expenses:Books $10.00 $3300.00
+10-Oct-01 Forecast transaction Expenses:Books $10.00 $3310.00
+10-Nov-01 Forecast transaction Expenses:Books $10.00 $3320.00
+10-Dec-01 Forecast transaction Expenses:Books $10.00 $3330.00
+11-Jan-01 Forecast transaction Expenses:Books $10.00 $3340.00
+11-Feb-01 Forecast transaction Expenses:Books $10.00 $3350.00
+11-Mar-01 Forecast transaction Expenses:Books $10.00 $3360.00
+11-Apr-01 Forecast transaction Expenses:Books $10.00 $3370.00
+11-May-01 Forecast transaction Expenses:Books $10.00 $3380.00
+11-Jun-01 Forecast transaction Expenses:Books $10.00 $3390.00
+11-Jul-01 Forecast transaction Expenses:Books $10.00 $3400.00
+11-Aug-01 Forecast transaction Expenses:Books $10.00 $3410.00
+11-Sep-01 Forecast transaction Expenses:Books $10.00 $3420.00
+11-Oct-01 Forecast transaction Expenses:Books $10.00 $3430.00
+11-Nov-01 Forecast transaction Expenses:Books $10.00 $3440.00
+11-Dec-01 Forecast transaction Expenses:Books $10.00 $3450.00
+12-Jan-01 Forecast transaction Expenses:Books $10.00 $3460.00
+12-Feb-01 Forecast transaction Expenses:Books $10.00 $3470.00
+12-Mar-01 Forecast transaction Expenses:Books $10.00 $3480.00
+12-Apr-01 Forecast transaction Expenses:Books $10.00 $3490.00
>>>2
=== 0
diff --git a/test/regress/E627C594.test b/test/regress/E627C594.test
index 0dfbf778..ba48a0c7 100644
--- a/test/regress/E627C594.test
+++ b/test/regress/E627C594.test
@@ -10,6 +10,8 @@ reg --forecast-while="d<[2010/03/01]" --now=2009/11/01
>>>1
09-Nov-01 Sample Expenses:Food:Dining $20.00 $20.00
Assets $-20.00 0
+09-Dec-01 Forecast transaction Expenses:Food $500.00 $500.00
+09-Dec-01 Forecast transaction Assets $-500.00 0
10-Jan-01 Forecast transaction Expenses:Food $500.00 $500.00
10-Jan-01 Forecast transaction Assets $-500.00 0
10-Feb-01 Forecast transaction Expenses:Food $500.00 $500.00