ledger/emacs.cc
John Wiegley 858978de89 Journal data structures now use date_t instead of datetime_t.
This means transactions can only have day-level granularity -- which has
always been the case from an data file point of view.  The advantage to this
restriction is that reports will now be immune from daylight savings related
bugs, where a transaction falls to the wrong side of a --monthly report, for
example.
2008-08-01 17:37:22 -04:00

78 lines
1.6 KiB
C++

#include "emacs.h"
namespace ledger {
void format_emacs_xacts::write_entry(entry_t& entry)
{
int idx = entry.src_idx;
foreach (const path& path, entry.journal->sources)
if (! idx--) {
out << "\"" << path << "\" ";
break;
}
out << (static_cast<unsigned long>(entry.beg_line) + 1) << " ";
tm when = gregorian::to_tm(entry.date());
std::time_t date = std::mktime(&when); // jww (2008-04-20): Is this GMT or local?
out << "(" << (date / 65536) << " " << (date % 65536) << " 0) ";
if (! entry.code)
out << "nil ";
else
out << "\"" << *entry.code << "\" ";
if (entry.payee.empty())
out << "nil";
else
out << "\"" << entry.payee << "\"";
out << "\n";
}
void format_emacs_xacts::operator()(xact_t& xact)
{
if (! xact_has_xdata(xact) ||
! (xact_xdata_(xact).dflags & XACT_DISPLAYED)) {
if (! last_entry) {
out << "((";
write_entry(*xact.entry);
}
else if (xact.entry != last_entry) {
out << ")\n (";
write_entry(*xact.entry);
}
else {
out << "\n";
}
out << " (" << (static_cast<unsigned long>(xact.beg_line) + 1) << " ";
out << "\"" << xact_account(xact)->fullname() << "\" \""
<< xact.amount << "\"";
switch (xact.state) {
case xact_t::CLEARED:
out << " t";
break;
case xact_t::PENDING:
out << " pending";
break;
default:
out << " nil";
break;
}
if (xact.cost)
out << " \"" << *xact.cost << "\"";
if (xact.note)
out << " \"" << *xact.note << "\"";
out << ")";
last_entry = xact.entry;
xact_xdata(xact).dflags |= XACT_DISPLAYED;
}
}
} // namespace ledger