diff options
author | John Wiegley <johnw@newartisans.com> | 2009-11-11 01:17:29 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-11-11 01:17:29 -0500 |
commit | eb772893b00119ead26d8662d73460651cafe11d (patch) | |
tree | e901434a5079b09cd67ea46e87c6a0bddc7f7ac4 /src | |
parent | b62b03335f33a6a0ae422605b8b6271add849aa6 (diff) | |
download | fork-ledger-eb772893b00119ead26d8662d73460651cafe11d.tar.gz fork-ledger-eb772893b00119ead26d8662d73460651cafe11d.tar.bz2 fork-ledger-eb772893b00119ead26d8662d73460651cafe11d.zip |
Timeclock entries can now have notes
Example of a tagged entry:
i 2009/11/01 12:00:00 Account Payee ; :Foo:
o 2009/11/01 13:00:00
Two spaces or a tab must separate account from payee, and payee from
note.
Diffstat (limited to 'src')
-rw-r--r-- | src/textual.cc | 22 | ||||
-rw-r--r-- | src/timelog.cc | 23 | ||||
-rw-r--r-- | src/timelog.h | 20 |
3 files changed, 47 insertions, 18 deletions
diff --git a/src/textual.cc b/src/textual.cc index bd7333d2..844edad3 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -413,11 +413,18 @@ void instance_t::clock_in_directive(char * line, { string datetime(line, 2, 19); - char * p = skip_ws(line + 22); - char * n = next_element(p, true); + char * p = skip_ws(line + 22); + char * n = next_element(p, true); + char * end = n ? next_element(n, true) : NULL; + + if (end && *end == ';') + end = skip_ws(end + 1); + else + end = NULL; timelog.clock_in(parse_datetime(datetime, current_year), - account_stack.front()->find_account(p), n ? n : ""); + account_stack.front()->find_account(p), + n ? n : "", end ? end : ""); } void instance_t::clock_out_directive(char * line, @@ -427,9 +434,16 @@ void instance_t::clock_out_directive(char * line, char * p = skip_ws(line + 22); char * n = next_element(p, true); + char * end = n ? next_element(n, true) : NULL; + + if (end && *end == ';') + end = skip_ws(end + 1); + else + end = NULL; timelog.clock_out(parse_datetime(datetime, current_year), - p ? account_stack.front()->find_account(p) : NULL, n ? n : ""); + p ? account_stack.front()->find_account(p) : NULL, + n ? n : "", end ? end : ""); count++; } diff --git a/src/timelog.cc b/src/timelog.cc index f7b79b9a..dc3d3496 100644 --- a/src/timelog.cc +++ b/src/timelog.cc @@ -44,6 +44,7 @@ namespace { const datetime_t& when, account_t * account, const char * desc, + const char * note, journal_t& journal) { time_xact_t event; @@ -82,11 +83,19 @@ namespace { desc = NULL; } + if (note && event.note.empty()) { + event.note = note; + note = NULL; + } + std::auto_ptr<xact_t> curr(new xact_t); curr->_date = when.date(); curr->code = desc ? desc : ""; curr->payee = event.desc; + if (! event.note.empty()) + curr->append_note(event.note.c_str()); + if (when < event.checkin) throw parse_error (_("Timelog check-out date less than corresponding check-in")); @@ -119,8 +128,8 @@ time_log_t::~time_log_t() accounts.push_back(time_xact.account); foreach (account_t * account, accounts) - clock_out_from_timelog(time_xacts, CURRENT_TIME(), account, NULL, - journal); + clock_out_from_timelog(time_xacts, CURRENT_TIME(), account, + NULL, NULL, journal); assert(time_xacts.empty()); } @@ -128,9 +137,10 @@ time_log_t::~time_log_t() void time_log_t::clock_in(const datetime_t& checkin, account_t * account, - const string& desc) + const string& desc, + const string& note) { - time_xact_t event(checkin, account, desc); + time_xact_t event(checkin, account, desc, note); if (! time_xacts.empty()) { foreach (time_xact_t& time_xact, time_xacts) { @@ -144,13 +154,14 @@ void time_log_t::clock_in(const datetime_t& checkin, void time_log_t::clock_out(const datetime_t& checkin, account_t * account, - const string& desc) + const string& desc, + const string& note) { if (time_xacts.empty()) throw std::logic_error(_("Timelog check-out event without a check-in")); clock_out_from_timelog(time_xacts, checkin, account, desc.c_str(), - journal); + note.c_str(), journal); } } // namespace ledger diff --git a/src/timelog.h b/src/timelog.h index 7d79af3e..d0519ce4 100644 --- a/src/timelog.h +++ b/src/timelog.h @@ -56,19 +56,21 @@ public: datetime_t checkin; account_t * account; string desc; + string note; time_xact_t() : account(NULL) { TRACE_CTOR(time_xact_t, ""); } time_xact_t(const datetime_t& _checkin, - account_t * _account = NULL, - const string& _desc = "") - : checkin(_checkin), account(_account), desc(_desc) { - TRACE_CTOR(time_xact_t, "const datetime_t&, account_t *, const string&"); + account_t * _account = NULL, + const string& _desc = "", + const string& _note = "") + : checkin(_checkin), account(_account), desc(_desc), note(_note) { + TRACE_CTOR(time_xact_t, "const datetime_t&, account_t *, string, string"); } time_xact_t(const time_xact_t& xact) : checkin(xact.checkin), account(xact.account), - desc(xact.desc) { + desc(xact.desc), note(xact.note) { TRACE_CTOR(time_xact_t, "copy"); } ~time_xact_t() throw() { @@ -79,7 +81,7 @@ public: class time_log_t { std::list<time_xact_t> time_xacts; - journal_t& journal; + journal_t& journal; public: time_log_t(journal_t& _journal) : journal(_journal) { @@ -89,11 +91,13 @@ public: void clock_in(const datetime_t& checkin, account_t * account = NULL, - const string& desc = ""); + const string& desc = "", + const string& note = ""); void clock_out(const datetime_t& checkin, account_t * account = NULL, - const string& desc = ""); + const string& desc = "", + const string& note = ""); }; } // namespace ledger |