From 5a93d4819e5fc753352618b729e0fe45532166b9 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Tue, 28 Mar 2006 05:24:02 +0000 Subject: Reworked the way date/times are handled. --- xml.cc | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'xml.cc') diff --git a/xml.cc b/xml.cc index 23bb8d84..418c6bf7 100644 --- a/xml.cc +++ b/xml.cc @@ -12,13 +12,13 @@ extern "C" { #include // expat XML parser #elif defined(HAVE_XMLPARSE) #include // expat XML parser -#else -#error "No XML parser library defined." #endif } namespace ledger { +#if defined(HAVE_EXPAT) || defined(HAVE_XMLPARSE) + static XML_Parser current_parser; static unsigned int count; @@ -83,10 +83,10 @@ static void endElement(void *userData, const char *name) curr_entry = NULL; } else if (std::strcmp(name, "en:date") == 0) { - quick_parse_date(data.c_str(), &curr_entry->_date); + curr_entry->_date = data; } else if (std::strcmp(name, "en:date_eff") == 0) { - quick_parse_date(data.c_str(), &curr_entry->_date_eff); + curr_entry->_date_eff = data; } else if (std::strcmp(name, "en:code") == 0) { curr_entry->code = data; @@ -246,6 +246,8 @@ unsigned int xml_parser_t::parse(std::istream& in, return count; } +#endif // defined(HAVE_EXPAT) || defined(HAVE_XMLPARSE) + void xml_write_amount(std::ostream& out, const amount_t& amount, const int depth = 0) { @@ -367,16 +369,14 @@ void output_xml_string(std::ostream& out, const std::string& str) void format_xml_entries::format_last_entry() { - char buf[32]; - std::strftime(buf, 31, "%Y/%m/%d", std::localtime(&last_entry->_date)); - output_stream << " \n" - << " " << buf << "\n"; + << " " << last_entry->_date.to_string("%Y/%m/%d") + << "\n"; - if (last_entry->_date_eff) { - std::strftime(buf, 31, "%Y/%m/%d", std::localtime(&last_entry->_date_eff)); - output_stream << " " << buf << "\n"; - } + if (last_entry->_date_eff) + output_stream << " " + << last_entry->_date_eff.to_string("%Y/%m/%d") + << "\n"; if (! last_entry->code.empty()) { output_stream << " "; @@ -403,14 +403,15 @@ void format_xml_entries::format_last_entry() output_stream << " \n"; - if ((*i)->_date) { - std::strftime(buf, 31, "%Y/%m/%d", std::localtime(&(*i)->_date)); - output_stream << " " << buf << "\n"; - } - if ((*i)->_date_eff) { - std::strftime(buf, 31, "%Y/%m/%d", std::localtime(&(*i)->_date_eff)); - output_stream << " " << buf << "\n"; - } + if ((*i)->_date) + output_stream << " " + << (*i)->_date.to_string("%Y/%m/%d") + << "\n"; + + if ((*i)->_date_eff) + output_stream << " " + << (*i)->_date_eff.to_string("%Y/%m/%d") + << "\n"; if ((*i)->state == transaction_t::CLEARED) output_stream << " \n"; -- cgit v1.2.3