summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-03-17 05:27:43 -0500
committerJohn Wiegley <johnw@newartisans.com>2012-03-17 05:27:43 -0500
commit22c1b867f03e4a495f9e47c899d1fdfcaec3a659 (patch)
tree851bf7423959048cf8f26d19bd7880450a97495e /src
parent018a2a8e7b1ad490e3ff69f3014aeb51abb80929 (diff)
downloadfork-ledger-22c1b867f03e4a495f9e47c899d1fdfcaec3a659.tar.gz
fork-ledger-22c1b867f03e4a495f9e47c899d1fdfcaec3a659.tar.bz2
fork-ledger-22c1b867f03e4a495f9e47c899d1fdfcaec3a659.zip
Added option --day-break
Diffstat (limited to 'src')
-rw-r--r--src/journal.cc1
-rw-r--r--src/journal.h1
-rw-r--r--src/session.cc3
-rw-r--r--src/session.h2
-rw-r--r--src/textual.cc3
-rw-r--r--src/timelog.cc101
-rw-r--r--src/timelog.h2
7 files changed, 77 insertions, 36 deletions
diff --git a/src/journal.cc b/src/journal.cc
index 37eacdaf..be6a8e51 100644
--- a/src/journal.cc
+++ b/src/journal.cc
@@ -94,6 +94,7 @@ void journal_t::initialize()
was_loaded = false;
force_checking = false;
check_payees = false;
+ day_break = false;
checking_style = CHECK_PERMISSIVE;
}
diff --git a/src/journal.h b/src/journal.h
index ca73c415..759826a0 100644
--- a/src/journal.h
+++ b/src/journal.h
@@ -130,6 +130,7 @@ public:
bool was_loaded;
bool force_checking;
bool check_payees;
+ bool day_break;
payee_mappings_t payee_mappings;
account_mappings_t account_mappings;
accounts_map account_aliases;
diff --git a/src/session.cc b/src/session.cc
index 76061de7..5c9e4fd4 100644
--- a/src/session.cc
+++ b/src/session.cc
@@ -105,6 +105,8 @@ std::size_t session_t::read_data(const string& master_account)
journal->force_checking = true;
if (HANDLED(check_payees))
journal->check_payees = true;
+ if (HANDLED(day_break))
+ journal->day_break = true;
if (HANDLED(permissive))
journal->checking_style = journal_t::CHECK_PERMISSIVE;
@@ -320,6 +322,7 @@ option_t<session_t> * session_t::lookup_option(const char * p)
case 'd':
OPT(download); // -Q
else OPT(decimal_comma);
+ else OPT(day_break);
break;
case 'e':
OPT(explicit);
diff --git a/src/session.h b/src/session.h
index 962664ef..a0aba91b 100644
--- a/src/session.h
+++ b/src/session.h
@@ -97,6 +97,7 @@ public:
{
HANDLER(cache_).report(out);
HANDLER(check_payees).report(out);
+ HANDLER(day_break).report(out);
HANDLER(download).report(out);
HANDLER(decimal_comma).report(out);
HANDLER(file_).report(out);
@@ -122,6 +123,7 @@ public:
OPTION(session_t, cache_);
OPTION(session_t, check_payees);
+ OPTION(session_t, day_break);
OPTION(session_t, download); // -Q
OPTION_(session_t, decimal_comma, DO() {
diff --git a/src/textual.cc b/src/textual.cc
index 3555ea4d..8856af5d 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -486,8 +486,7 @@ void instance_t::clock_out_directive(char * line, bool /*capitalized*/)
n ? n : "",
end ? end : "");
- timelog.clock_out(event);
- context.count++;
+ context.count += timelog.clock_out(event);
}
#endif // TIMELOG_SUPPORT
diff --git a/src/timelog.cc b/src/timelog.cc
index 00cefe10..e84e4188 100644
--- a/src/timelog.cc
+++ b/src/timelog.cc
@@ -41,9 +41,43 @@
namespace ledger {
namespace {
- void clock_out_from_timelog(std::list<time_xact_t>& time_xacts,
- time_xact_t out_event,
- parse_context_t& context)
+ void create_timelog_xact(const time_xact_t& in_event,
+ const time_xact_t& out_event,
+ parse_context_t& context)
+ {
+ unique_ptr<xact_t> curr(new xact_t);
+ curr->_date = in_event.checkin.date();
+ curr->code = out_event.desc; // if it wasn't used above
+ curr->payee = in_event.desc;
+ curr->pos = in_event.position;
+
+ if (! in_event.note.empty())
+ curr->append_note(in_event.note.c_str(), *context.scope);
+
+ char buf[32];
+ std::sprintf(buf, "%lds", long((out_event.checkin - in_event.checkin)
+ .total_seconds()));
+ amount_t amt;
+ amt.parse(buf);
+ VERIFY(amt.valid());
+
+ post_t * post = new post_t(in_event.account, amt, POST_VIRTUAL);
+ post->set_state(item_t::CLEARED);
+ post->pos = in_event.position;
+ post->checkin = in_event.checkin;
+ post->checkout = out_event.checkin;
+ curr->add_post(post);
+ in_event.account->add_post(post);
+
+ if (! context.journal->add_xact(curr.get()))
+ throw parse_error(_("Failed to record 'out' timelog transaction"));
+ else
+ curr.release();
+ }
+
+ std::size_t clock_out_from_timelog(std::list<time_xact_t>& time_xacts,
+ time_xact_t out_event,
+ parse_context_t& context)
{
time_xact_t event;
@@ -93,34 +127,35 @@ namespace {
if (! out_event.note.empty() && event.note.empty())
event.note = out_event.note;
- unique_ptr<xact_t> curr(new xact_t);
- curr->_date = event.checkin.date();
- curr->code = out_event.desc; // if it wasn't used above
- curr->payee = event.desc;
- curr->pos = event.position;
-
- if (! event.note.empty())
- curr->append_note(event.note.c_str(), *context.scope);
-
- char buf[32];
- std::sprintf(buf, "%lds", long((out_event.checkin - event.checkin)
- .total_seconds()));
- amount_t amt;
- amt.parse(buf);
- VERIFY(amt.valid());
-
- post_t * post = new post_t(event.account, amt, POST_VIRTUAL);
- post->set_state(item_t::CLEARED);
- post->pos = event.position;
- post->checkin = event.checkin;
- post->checkout = out_event.checkin;
- curr->add_post(post);
- event.account->add_post(post);
-
- if (! context.journal->add_xact(curr.get()))
- throw parse_error(_("Failed to record 'out' timelog transaction"));
- else
- curr.release();
+ if (! context.journal->day_break) {
+ create_timelog_xact(event, out_event, context);
+ return 1;
+ } else {
+ time_xact_t begin(event);
+ std::size_t xact_count = 0;
+
+ while (begin.checkin < out_event.checkin) {
+ DEBUG("timelog", "begin.checkin: " << begin.checkin);
+ datetime_t days_end(begin.checkin.date(), time_duration_t(23, 59, 59));
+ days_end += seconds(1);
+ DEBUG("timelog", "days_end: " << days_end);
+
+ if (out_event.checkin <= days_end) {
+ create_timelog_xact(begin, out_event, context);
+ ++xact_count;
+ break;
+ } else {
+ time_xact_t end(out_event);
+ end.checkin = days_end;
+ DEBUG("timelog", "end.checkin: " << end.checkin);
+ create_timelog_xact(begin, end, context);
+ ++xact_count;
+
+ begin.checkin = end.checkin;
+ }
+ }
+ return xact_count;
+ }
}
} // unnamed namespace
@@ -155,12 +190,12 @@ void time_log_t::clock_in(time_xact_t event)
time_xacts.push_back(event);
}
-void time_log_t::clock_out(time_xact_t event)
+std::size_t time_log_t::clock_out(time_xact_t event)
{
if (time_xacts.empty())
throw std::logic_error(_("Timelog check-out event without a check-in"));
- clock_out_from_timelog(time_xacts, event, context);
+ return clock_out_from_timelog(time_xacts, event, context);
}
} // namespace ledger
diff --git a/src/timelog.h b/src/timelog.h
index ed5a2d36..857952ff 100644
--- a/src/timelog.h
+++ b/src/timelog.h
@@ -98,7 +98,7 @@ public:
}
void clock_in(time_xact_t event);
- void clock_out(time_xact_t event);
+ std::size_t clock_out(time_xact_t event);
void close();
};