diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-11 21:32:18 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-11 21:32:32 -0500 |
commit | 67c9cf134d1403657c766e72b96d692a7d538f65 (patch) | |
tree | cd72247ddf240746b524c8fecf6d10f8667b37e4 /src | |
parent | c22b8457eff27f5227fdf452e036b33e41e229c2 (diff) | |
download | fork-ledger-67c9cf134d1403657c766e72b96d692a7d538f65.tar.gz fork-ledger-67c9cf134d1403657c766e72b96d692a7d538f65.tar.bz2 fork-ledger-67c9cf134d1403657c766e72b96d692a7d538f65.zip |
Added --date, similar to --account and --payee
This lets you do things like store a date as the value of a tag, then
run:
ledger --date='has_tag("Foo") ? to_date(tag("Foo")) : date' reg
Diffstat (limited to 'src')
-rw-r--r-- | src/chain.cc | 5 | ||||
-rw-r--r-- | src/filters.cc | 11 | ||||
-rw-r--r-- | src/filters.h | 5 | ||||
-rw-r--r-- | src/item.h | 6 | ||||
-rw-r--r-- | src/report.cc | 1 | ||||
-rw-r--r-- | src/report.h | 2 | ||||
-rw-r--r-- | src/value.cc | 6 |
7 files changed, 31 insertions, 5 deletions
diff --git a/src/chain.cc b/src/chain.cc index 5839bd9e..55ef467b 100644 --- a/src/chain.cc +++ b/src/chain.cc @@ -159,6 +159,11 @@ post_handler_ptr chain_post_handlers(report_t& report, handler.reset(new sort_posts(handler, "date")); } + if (report.HANDLED(date_)) + handler.reset(new transfer_details(handler, transfer_details::SET_DATE, + report.session.journal->master, + report.HANDLER(date_).str(), + report)); if (report.HANDLED(account_)) handler.reset(new transfer_details(handler, transfer_details::SET_ACCOUNT, report.session.journal->master, diff --git a/src/filters.cc b/src/filters.cc index 4b54a0cd..8c5d099e 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -706,22 +706,27 @@ void transfer_details::operator()(post_t& post) temp.set_state(post.state()); bind_scope_t bound_scope(scope, temp); + value_t substitute(expr.calc(bound_scope)); switch (which_element) { - case SET_PAYEE: - xact.payee = expr.calc(bound_scope).to_string(); + case SET_DATE: + xact.set_date(substitute.to_date()); break; case SET_ACCOUNT: { std::list<string> account_names; temp.account->remove_post(&temp); - split_string(expr.calc(bound_scope).to_string(), ':', account_names); + split_string(substitute.to_string(), ':', account_names); temp.account = create_temp_account_from_path(account_names, temps, xact.journal->master); temp.account->add_post(&temp); break; } + case SET_PAYEE: + xact.payee = substitute.to_string(); + break; + default: assert(false); break; diff --git a/src/filters.h b/src/filters.h index ba3692ac..cc3729ea 100644 --- a/src/filters.h +++ b/src/filters.h @@ -550,8 +550,9 @@ class transfer_details : public item_handler<post_t> public: enum element_t { - SET_PAYEE, - SET_ACCOUNT + SET_DATE, + SET_ACCOUNT, + SET_PAYEE } which_element; transfer_details(post_handler_ptr handler, @@ -172,6 +172,12 @@ public: virtual optional<date_t> effective_date() const { return _date_eff; } + virtual void set_date(const date_t& date) { + if (use_effective_date) + _date_eff = date; + else + _date = date; + } void set_state(state_t new_state) { _state = new_state; diff --git a/src/report.cc b/src/report.cc index b866970f..23326fec 100644 --- a/src/report.cc +++ b/src/report.cc @@ -561,6 +561,7 @@ option_t<report_t> * report_t::lookup_option(const char * p) break; case 'd': OPT(daily); + else OPT(date_); else OPT(date_format_); else OPT(datetime_format_); else OPT(depth_); diff --git a/src/report.h b/src/report.h index e27abbf9..2181c49a 100644 --- a/src/report.h +++ b/src/report.h @@ -217,6 +217,7 @@ public: HANDLER(csv_format_).report(out); HANDLER(current).report(out); HANDLER(daily).report(out); + HANDLER(date_).report(out); HANDLER(date_format_).report(out); HANDLER(datetime_format_).report(out); HANDLER(depth_).report(out); @@ -450,6 +451,7 @@ public: parent->HANDLER(period_).on(string("--daily"), "daily"); }); + OPTION(report_t, date_); OPTION(report_t, date_format_); OPTION(report_t, datetime_format_); diff --git a/src/value.cc b/src/value.cc index ae86eb7c..910a9140 100644 --- a/src/value.cc +++ b/src/value.cc @@ -1146,6 +1146,12 @@ void value_t::in_place_cast(type_t cast_type) case AMOUNT: set_amount(amount_t(as_string())); return; + case DATE: + set_date(parse_date(as_string())); + return; + case DATETIME: + set_datetime(parse_datetime(as_string())); + return; case MASK: set_mask(as_string()); return; |