From 4edd39cdbdd3378408b65c4e3f08ab493d34458a Mon Sep 17 00:00:00 2001 From: randomdan Date: Sun, 3 Feb 2013 12:48:12 +0000 Subject: Add support for writing dates in a custom format in XML presenter --- project2/xml/xmlPresenter.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/project2/xml/xmlPresenter.cpp b/project2/xml/xmlPresenter.cpp index 075518c..2d72561 100644 --- a/project2/xml/xmlPresenter.cpp +++ b/project2/xml/xmlPresenter.cpp @@ -1,4 +1,5 @@ #include +#include #include "xmlPresenter.h" #include "scriptLoader.h" #include "scriptStorage.h" @@ -11,7 +12,7 @@ class XmlPresenterLoader : public PresenterLoader::For { public: XmlPresenterLoader() : - opts("XML Cache options") + opts("XML Presenter options") { opts ("presenter.xml.typeid.null", Options::value(&typeidNull, false), @@ -30,6 +31,8 @@ class XmlPresenterLoader : public PresenterLoader::For { "Output a date attribute in standard format") ("presenter.xml.datetime.timeattr", Options::value(&timeAttr, true), "Output a time attribute in standard format") + ("presenter.xml.datetime.customformat", Options::value(&customFormat), + "Output a time attribute in this custom format") ; } @@ -46,6 +49,7 @@ class XmlPresenterLoader : public PresenterLoader::For { static bool typeidDateTime; static bool dateAttr; static bool timeAttr; + static boost::optional customFormat; private: Options opts; }; @@ -58,6 +62,7 @@ bool XmlPresenterLoader::typeidFloat; bool XmlPresenterLoader::typeidDateTime; bool XmlPresenterLoader::dateAttr; bool XmlPresenterLoader::timeAttr; +boost::optional XmlPresenterLoader::customFormat; DECLARE_CUSTOM_COMPONENT_LOADER("xml", XmlPresenter, XmlPresenterLoader, PresenterLoader) @@ -204,6 +209,14 @@ class XmlNodeWriter : public boost::static_visitor { if (XmlPresenterLoader::dateAttr) { node->set_attribute("date", boost::gregorian::to_iso_extended_string(i.date())); } + if (!!XmlPresenterLoader::customFormat) { + std::stringstream ss; + boost::date_time::time_facet * ft = new boost::date_time::time_facet(); + ss.imbue(std::locale(ss.getloc(), ft)); + ft->format(XmlPresenterLoader::customFormat->c_str()); + ss << boost::get(i); + node->set_attribute("custom", ss.str()); + } return true; } -- cgit v1.2.3