From 97ec24544e783abd9edecdc13e8deba99baee47b Mon Sep 17 00:00:00 2001 From: Peter Pickford Date: Fri, 4 Mar 2016 19:26:19 -0800 Subject: [PATCH] Periods should be initialized from from/since clause rather than earliest transaction date Bug 1159 Use interval start date (period from/since) to initialize first period. This allows the offset of a period start to be specified -p 'every 12 months from 2000-04-01' will have periods yyyy-04-01 to yyyy-03-31 .... If no from/since is specified for the period the first transaction date reported is used to initialize the period as before. added test case regress/1159.test --- src/filters.cc | 10 ++++++---- test/regress/1159.test | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 test/regress/1159.test diff --git a/src/filters.cc b/src/filters.cc index 1d7832ca8..8aa1218bd 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -982,10 +982,12 @@ void interval_posts::flush() std::stable_sort(all_posts.begin(), all_posts.end(), sort_posts_by_date()); - // Determine the beginning interval by using the earliest post - if (all_posts.size() > 0 && all_posts.front() && - ! interval.find_period(all_posts.front()->date())) - throw_(std::logic_error, _("Failed to find period for interval report")); + // only if the interval has no start use the earliest post + if (!(interval.begin() && interval.find_period(*interval.begin()))) + // Determine the beginning interval by using the earliest post + if (all_posts.size() > 0 && all_posts.front() + && !interval.find_period(all_posts.front()->date())) + throw_(std::logic_error, _("Failed to find period for interval report")); // Walk the interval forward reporting all posts within each one // before moving on, until we reach the end of all_posts diff --git a/test/regress/1159.test b/test/regress/1159.test new file mode 100644 index 000000000..72da771a1 --- /dev/null +++ b/test/regress/1159.test @@ -0,0 +1,29 @@ +2003/09/13 a payee ; sat + A $100.00 + B + +2003/09/14 a payee ; mon + A $100.00 + B + +2004/10/15 a payee ; fri + A $50.00 + B + +2004/10/19 a payee ; tue + A $50.00 + B + +;sun first day of month +test reg -p "every 12 months from 2001/04/01" +03-Apr-01 - 04-Mar-31 A $200.00 $200.00 + B $-200.00 0 +04-Apr-01 - 05-Mar-31 A $100.00 $100.00 + B $-100.00 0 +end test +test reg -p 'every 12 months' +03-Sep-01 - 04-Aug-31 A $200.00 $200.00 + B $-200.00 0 +04-Sep-01 - 05-Aug-31 A $100.00 $100.00 + B $-100.00 0 +end test