(clock_out_from_timelog): If a timelog file is left "open", clock out
at the present time.
This commit is contained in:
parent
282414d2f6
commit
688f572ffd
1 changed files with 32 additions and 22 deletions
54
textual.cc
54
textual.cc
|
|
@ -329,6 +329,32 @@ bool textual_parser_t::test(std::istream& in) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void clock_out_from_timelog(const std::time_t when,
|
||||||
|
journal_t * journal)
|
||||||
|
{
|
||||||
|
std::auto_ptr<entry_t> curr(new entry_t);
|
||||||
|
curr->date = when;
|
||||||
|
curr->state = entry_t::CLEARED;
|
||||||
|
curr->code = "";
|
||||||
|
curr->payee = last_desc;
|
||||||
|
|
||||||
|
double diff = std::difftime(curr->date, time_in);
|
||||||
|
char buf[32];
|
||||||
|
std::sprintf(buf, "%lds", long(diff));
|
||||||
|
amount_t amt;
|
||||||
|
amt.parse(buf);
|
||||||
|
|
||||||
|
transaction_t * xact
|
||||||
|
= new transaction_t(last_account, amt, TRANSACTION_VIRTUAL);
|
||||||
|
curr->add_transaction(xact);
|
||||||
|
|
||||||
|
if (! journal->add_entry(curr.get()))
|
||||||
|
throw parse_error(path, linenum,
|
||||||
|
"Failed to record 'out' timelog entry");
|
||||||
|
else
|
||||||
|
curr.release();
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int textual_parser_t::parse(std::istream& in,
|
unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
journal_t * journal,
|
journal_t * journal,
|
||||||
account_t * master,
|
account_t * master,
|
||||||
|
|
@ -404,28 +430,7 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
|
|
||||||
struct std::tm when;
|
struct std::tm when;
|
||||||
if (strptime(date.c_str(), "%Y/%m/%d %H:%M:%S", &when)) {
|
if (strptime(date.c_str(), "%Y/%m/%d %H:%M:%S", &when)) {
|
||||||
std::auto_ptr<entry_t> curr(new entry_t);
|
clock_out_from_timelog(std::mktime(&when), journal);
|
||||||
curr->date = std::mktime(&when);
|
|
||||||
curr->state = entry_t::CLEARED;
|
|
||||||
curr->code = "";
|
|
||||||
curr->payee = last_desc;
|
|
||||||
|
|
||||||
double diff = std::difftime(curr->date, time_in);
|
|
||||||
char buf[32];
|
|
||||||
std::sprintf(buf, "%lds", long(diff));
|
|
||||||
amount_t amt;
|
|
||||||
amt.parse(buf);
|
|
||||||
|
|
||||||
transaction_t * xact
|
|
||||||
= new transaction_t(last_account, amt, TRANSACTION_VIRTUAL);
|
|
||||||
curr->add_transaction(xact);
|
|
||||||
|
|
||||||
if (! journal->add_entry(curr.get()))
|
|
||||||
throw parse_error(path, linenum,
|
|
||||||
"Failed to record 'out' timelog entry");
|
|
||||||
else
|
|
||||||
curr.release();
|
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
} else {
|
} else {
|
||||||
throw parse_error(path, linenum, "Cannot parse timelog entry date");
|
throw parse_error(path, linenum, "Cannot parse timelog entry date");
|
||||||
|
|
@ -655,6 +660,11 @@ unsigned int textual_parser_t::parse(std::istream& in,
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
if (last_account) {
|
||||||
|
clock_out_from_timelog(now, journal);
|
||||||
|
last_account = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (added_auto_entry_hook)
|
if (added_auto_entry_hook)
|
||||||
journal->remove_entry_finalizer(&auto_entry_finalizer);
|
journal->remove_entry_finalizer(&auto_entry_finalizer);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue