diff options
author | randomdan <randomdan@localhost> | 2013-02-03 12:48:12 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2013-02-03 12:48:12 +0000 |
commit | a28fb37428dfbcfa3f2b08be458a8ceafa3e1ef1 (patch) | |
tree | 5aa57460a6d55e0ff93d23fe1ecd042e681d921f | |
parent | Fix issues with PQ connection errors not being handled correctly (diff) | |
download | project2-a28fb37428dfbcfa3f2b08be458a8ceafa3e1ef1.tar.bz2 project2-a28fb37428dfbcfa3f2b08be458a8ceafa3e1ef1.tar.xz project2-a28fb37428dfbcfa3f2b08be458a8ceafa3e1ef1.zip |
Add support for writing dates in a custom format in XML presenter
-rw-r--r-- | project2/xml/xmlPresenter.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
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 <pch.hpp> +#include <boost/date_time.hpp> #include "xmlPresenter.h" #include "scriptLoader.h" #include "scriptStorage.h" @@ -11,7 +12,7 @@ class XmlPresenterLoader : public PresenterLoader::For<XmlPresenter> { 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<XmlPresenter> { "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<XmlPresenter> { static bool typeidDateTime; static bool dateAttr; static bool timeAttr; + static boost::optional<std::string> customFormat; private: Options opts; }; @@ -58,6 +62,7 @@ bool XmlPresenterLoader::typeidFloat; bool XmlPresenterLoader::typeidDateTime; bool XmlPresenterLoader::dateAttr; bool XmlPresenterLoader::timeAttr; +boost::optional<std::string> XmlPresenterLoader::customFormat; DECLARE_CUSTOM_COMPONENT_LOADER("xml", XmlPresenter, XmlPresenterLoader, PresenterLoader) @@ -204,6 +209,14 @@ class XmlNodeWriter : public boost::static_visitor<bool> { 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<boost::posix_time::ptime, char> * ft = new boost::date_time::time_facet<boost::posix_time::ptime, char>(); + ss.imbue(std::locale(ss.getloc(), ft)); + ft->format(XmlPresenterLoader::customFormat->c_str()); + ss << boost::get<boost::posix_time::ptime>(i); + node->set_attribute("custom", ss.str()); + } return true; } |