summaryrefslogtreecommitdiff
path: root/src/global.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-06-17 17:15:29 +0100
committerJohn Wiegley <johnw@newartisans.com>2009-06-17 17:15:29 +0100
commita64c249efbf9447d1dca72668927dc017946ad5a (patch)
tree9912af9326ce200e218a461b16714275a7f45250 /src/global.cc
parentde50277abe0f2d1c8ff85d57fa70f30d177a2732 (diff)
downloadfork-ledger-a64c249efbf9447d1dca72668927dc017946ad5a.tar.gz
fork-ledger-a64c249efbf9447d1dca72668927dc017946ad5a.tar.bz2
fork-ledger-a64c249efbf9447d1dca72668927dc017946ad5a.zip
Allow --period flag to specify a report range
Diffstat (limited to 'src/global.cc')
-rw-r--r--src/global.cc29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/global.cc b/src/global.cc
index 38e0634e..60865284 100644
--- a/src/global.cc
+++ b/src/global.cc
@@ -138,7 +138,7 @@ void global_scope_t::report_error(const std::exception& err)
string context = error_context();
if (! context.empty())
std::cerr << context << std::endl;
-
+
std::cerr << _("Error: ") << err.what() << std::endl;
} else {
caught_signal = NONE_CAUGHT;
@@ -451,8 +451,31 @@ void global_scope_t::normalize_report_options(const string& verb)
if (verb[0] != 'b' && verb[0] != 'r')
rep.HANDLER(base).on_only(string("?normalize"));
- if (rep.HANDLED(period_) && ! rep.HANDLED(sort_all_))
- rep.HANDLER(sort_xacts_).on_only(string("?normalize"));
+ // If a time period was specified with -p, check whether it also gave a
+ // begin and/or end to the report period (though these can be overridden
+ // 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 (rep.HANDLED(period_)) {
+ if (! rep.HANDLED(sort_all_))
+ rep.HANDLER(sort_xacts_).on_only(string("?normalize"));
+
+ date_interval_t interval(rep.HANDLER(period_).str());
+
+ if (! rep.HANDLED(begin_) && interval.start) {
+ string predicate =
+ "date>=[" + to_iso_extended_string(*interval.start) + "]";
+ rep.HANDLER(limit_).on(string("--begin"), predicate);
+ }
+ if (! rep.HANDLED(end_) && interval.end) {
+ string predicate =
+ "date<[" + to_iso_extended_string(*interval.end) + "]";
+ rep.HANDLER(limit_).on(string("--end"), predicate);
+ }
+
+ if (! interval.duration)
+ rep.HANDLER(period_).off();
+ }
long cols = 0;
if (rep.HANDLED(columns_))