From e716980c7d4ae2a2852a7cd0e5c0cf52014ed787 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Sun, 28 Dec 2014 13:32:22 +0100 Subject: Fix plain year directive Only Y2014 or apply year 2014 would actually set the year for the following transactions; year 2014 would silently do nothing. --- src/textual.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/textual.cc b/src/textual.cc index b2f19be4..5862c26c 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -1375,6 +1375,13 @@ bool instance_t::general_directive(char * line) return true; } break; + + case 'y': + if (std::strcmp(p, "year") == 0) { + apply_year_directive(arg); + return true; + } + break; } if (expr_t::ptr_op_t op = lookup(symbol_t::DIRECTIVE, p)) { -- cgit v1.2.3 From 0462c887ae5814d08de7d2a860c41bb1a07bee52 Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Sun, 28 Dec 2014 13:42:02 +0100 Subject: Improve error handling when parsing year directives MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A literal Y directive or ‘year’ directive with an empty or invalid argument, e.g. ‘2o14’ (that is a small letter ‘oh’ instead of a zero) would fail with the following rather unhelpful error message: Error: bad lexical cast: source type value could not be interpreted as target --- src/textual.cc | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/textual.cc b/src/textual.cc index 5862c26c..f0df3b66 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -419,7 +419,9 @@ void instance_t::read_next_directive(bool& error_flag) price_xact_directive(line); break; case 'Y': // set the current year - apply_year_directive(line + 1); + if (std::strlen(line+1) == 0) + throw_(parse_error, _f("Directive '%1%' requires an argument") % line[0]); + apply_year_directive(line+1); break; } } @@ -863,14 +865,17 @@ void instance_t::apply_rate_directive(char * line) void instance_t::apply_year_directive(char * line) { - apply_stack.push_front(application_t("year", epoch)); - - // This must be set to the last day of the year, otherwise partial - // dates like "11/01" will refer to last year's november, not the - // current year. - unsigned short year(lexical_cast(skip_ws(line))); - DEBUG("times.epoch", "Setting current year to " << year); - epoch = datetime_t(date_t(year, 12, 31)); + try { + unsigned short year(lexical_cast(skip_ws(line))); + apply_stack.push_front(application_t("year", epoch)); + DEBUG("times.epoch", "Setting current year to " << year); + // This must be set to the last day of the year, otherwise partial + // dates like "11/01" will refer to last year's november, not the + // current year. + epoch = datetime_t(date_t(year, 12, 31)); + } catch(bad_lexical_cast &) { + throw_(parse_error, _f("Argument '%1%' not a valid year") % skip_ws(line)); + } } void instance_t::end_apply_directive(char * kind) -- cgit v1.2.3 From ba35340ca9c7351beab0ff9fa7a58591eb6ad39f Mon Sep 17 00:00:00 2001 From: Alexis Hildebrandt Date: Sun, 28 Dec 2014 14:45:39 +0100 Subject: Bugfix 1038: empty reg report for this month period when year was specified with literal Y or year directive, but not when using apply year. --- src/textual.cc | 5 +++++ test/regress/1038_1.test | 18 ++++++++++++++++++ test/regress/1038_2.test | 18 ++++++++++++++++++ test/regress/1038_3.test | 20 ++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 test/regress/1038_1.test create mode 100644 test/regress/1038_2.test create mode 100644 test/regress/1038_3.test (limited to 'src') diff --git a/src/textual.cc b/src/textual.cc index f0df3b66..8007ca0d 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -285,6 +285,11 @@ void instance_t::parse() } } + if (apply_stack.front().value.type() == typeid(optional)) + epoch = boost::get >(apply_stack.front().value); + + apply_stack.pop_front(); + #if defined(TIMELOG_SUPPORT) timelog.close(); #endif // TIMELOG_SUPPORT diff --git a/test/regress/1038_1.test b/test/regress/1038_1.test new file mode 100644 index 00000000..c833816e --- /dev/null +++ b/test/regress/1038_1.test @@ -0,0 +1,18 @@ +Y2014 + +04/13 Bank + Expenses:Loan $400 + Assets:Cash + +05/13 Bug 1038 Test + Expenses:Some:Account $500 + Assets:Cash + +06/13 Landlord + Expenses:Rent $600 + Assets:Cash + +test reg --now 2014-05-14 -p 'this month' +14-May-13 Bug 1038 Test Expenses:Some:Account $500 $500 + Assets:Cash $-500 0 +end test diff --git a/test/regress/1038_2.test b/test/regress/1038_2.test new file mode 100644 index 00000000..ce0c046d --- /dev/null +++ b/test/regress/1038_2.test @@ -0,0 +1,18 @@ +year 2014 + +04/13 Bank + Expenses:Loan $400 + Assets:Cash + +05/13 Bug 1038 Test + Expenses:Some:Account $500 + Assets:Cash + +06/13 Landlord + Expenses:Rent $600 + Assets:Cash + +test reg --now 2014-05-14 -p 'this month' +14-May-13 Bug 1038 Test Expenses:Some:Account $500 $500 + Assets:Cash $-500 0 +end test diff --git a/test/regress/1038_3.test b/test/regress/1038_3.test new file mode 100644 index 00000000..0e277d71 --- /dev/null +++ b/test/regress/1038_3.test @@ -0,0 +1,20 @@ +apply year 2014 + +04/13 Bank + Expenses:Loan $400 + Assets:Cash + +05/13 Bug 1038 Test + Expenses:Some:Account $500 + Assets:Cash + +06/13 Landlord + Expenses:Rent $600 + Assets:Cash + +end apply + +test reg --now 2014-05-14 -p 'this month' +14-May-13 Bug 1038 Test Expenses:Some:Account $500 $500 + Assets:Cash $-500 0 +end test -- cgit v1.2.3