diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-22 21:56:19 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-22 21:56:19 -0400 |
commit | e8e28c794bfb12fe1c9562c5bd124688ce45fc8e (patch) | |
tree | 3a6dfcaba3fae13dce2286c917aa74969a7d5be9 /src/report.cc | |
parent | 0648c2f6dccb5c56e66d50a255177c92e46d5fea (diff) | |
download | fork-ledger-e8e28c794bfb12fe1c9562c5bd124688ce45fc8e.tar.gz fork-ledger-e8e28c794bfb12fe1c9562c5bd124688ce45fc8e.tar.bz2 fork-ledger-e8e28c794bfb12fe1c9562c5bd124688ce45fc8e.zip |
Added report query modifiers: for, since, until
Now instead of ledger reg expense -p "this month", you can say:
ledger reg expense for this month
And as a shorthand for "for until this month", you can just say "until
this month" or "since this month".
Diffstat (limited to 'src/report.cc')
-rw-r--r-- | src/report.cc | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/src/report.cc b/src/report.cc index 4a7ed2e5..9d733674 100644 --- a/src/report.cc +++ b/src/report.cc @@ -145,26 +145,8 @@ void report_t::normalize_options(const string& verb) // using -b or -e). Then, if no _duration_ was specified (such as monthly), // then ignore the period since the begin/end are the only interesting // details. - if (HANDLED(period_)) { - date_interval_t interval(HANDLER(period_).str()); - - optional<date_t> begin = interval.begin(); - optional<date_t> end = interval.end(); - - if (! HANDLED(begin_) && begin) { - string predicate = "date>=[" + to_iso_extended_string(*begin) + "]"; - HANDLER(limit_).on(string("?normalize"), predicate); - } - if (! HANDLED(end_) && end) { - string predicate = "date<[" + to_iso_extended_string(*end) + "]"; - HANDLER(limit_).on(string("?normalize"), predicate); - } - - if (! interval.duration) - HANDLER(period_).off(); - else if (! HANDLED(sort_all_)) - HANDLER(sort_xacts_).on_only(string("?normalize")); - } + if (HANDLED(period_)) + normalize_period(); // If -j or -J were specified, set the appropriate format string now so as // to avoid option ordering issues were we to have done it during the @@ -254,26 +236,52 @@ void report_t::normalize_options(const string& verb) } } +void report_t::normalize_period() +{ + date_interval_t interval(HANDLER(period_).str()); + + optional<date_t> begin = interval.begin(); + optional<date_t> end = interval.end(); + + if (! HANDLED(begin_) && begin) { + string predicate = "date>=[" + to_iso_extended_string(*begin) + "]"; + HANDLER(limit_).on(string("?normalize"), predicate); + } + if (! HANDLED(end_) && end) { + string predicate = "date<[" + to_iso_extended_string(*end) + "]"; + HANDLER(limit_).on(string("?normalize"), predicate); + } + + if (! interval.duration) + HANDLER(period_).off(); + else if (! HANDLED(sort_all_)) + HANDLER(sort_xacts_).on_only(string("?normalize")); +} + void report_t::parse_query_args(const value_t& args, const string& whence) { query_t query(args, what_to_keep()); - if (query.has_predicate(query_t::QUERY_LIMIT)) { - HANDLER(limit_) - .on(whence, query.get_predicate(query_t::QUERY_LIMIT).print_to_str()); - DEBUG("report.predicate", "Predicate = " << HANDLER(limit_).str()); + if (query.has_query(query_t::QUERY_LIMIT)) { + HANDLER(limit_).on(whence, query.get_query(query_t::QUERY_LIMIT)); + DEBUG("report.predicate", "Limit predicate = " << HANDLER(limit_).str()); } - if (query.has_predicate(query_t::QUERY_SHOW)) { - HANDLER(display_) - .on(whence, query.get_predicate(query_t::QUERY_SHOW).print_to_str()); + if (query.has_query(query_t::QUERY_SHOW)) { + HANDLER(display_).on(whence, query.get_query(query_t::QUERY_SHOW)); DEBUG("report.predicate", "Display predicate = " << HANDLER(display_).str()); } - if (query.has_predicate(query_t::QUERY_BOLD)) { - HANDLER(bold_if_) - .set_expr(whence, query.get_predicate(query_t::QUERY_BOLD).print_to_str()); - DEBUG("report.predicate", "Bolding predicate = " << HANDLER(display_).str()); + if (query.has_query(query_t::QUERY_BOLD)) { + HANDLER(bold_if_).set_expr(whence, query.get_query(query_t::QUERY_BOLD)); + DEBUG("report.predicate", "Bolding predicate = " << HANDLER(bold_if_).str()); + } + + if (query.has_query(query_t::QUERY_FOR)) { + HANDLER(period_).on(whence, query.get_query(query_t::QUERY_FOR)); + DEBUG("report.predicate", "Report period = " << HANDLER(period_).str()); + + normalize_period(); // it needs normalization } } |