c++ - How to read an ISO timezone with boost::date_time? -


i'm flabbergasted seems boost::date_time can write date/time strings cannot read.

consider following example code:

#include <boost/date_time/local_time/local_time.hpp> #include <iostream> #include <locale>  class pointtime : public boost::local_time::local_date_time {     typedef boost::local_time::local_time_input_facet   input_facet_t;     typedef boost::local_time::local_time_facet         output_face_t;    public:     static input_facet_t const s_input_facet;     static output_face_t const s_output_facet;     static std::locale const s_input_locale;     static std::locale const s_output_locale;    public:     pointtime(std::string const& str); };  pointtime::input_facet_t const pointtime::s_input_facet("%y-%m-%dt%h:%m:%s%q", 1); pointtime::output_face_t const pointtime::s_output_facet("%y-%m-%dt%h:%m:%s%q",     boost::local_time::local_time_facet::period_formatter_type(),     boost::local_time::local_time_facet::special_values_formatter_type(),     boost::local_time::local_time_facet::date_gen_formatter_type(),     1); std::locale const pointtime::s_input_locale(std::locale::classic(), &pointtime::s_input_facet); std::locale const pointtime::s_output_locale(std::locale::classic(), &pointtime::s_output_facet);  pointtime::pointtime(std::string const& str) : boost::local_time::local_date_time(boost::local_time::not_a_date_time) {   std::istringstream is(str);   is.imbue(s_input_locale);   >> *this;   std::string s;   >> s;   std::cout << "left after parsing: \"" << s << "\"." << std::endl; }  int main() {   std::string ts("2005-10-15t13:12:11-0700");   std::cout << "ts = " << ts << std::endl;    try   {     pointtime t(ts);     std::cout.imbue(pointtime::s_output_locale);     std::cout << "t =  " << t << std::endl;   }   catch (boost::bad_lexical_cast const& error)   {     std::cout << error.what() << std::endl;   }    return 0; } 

this outputs:

ts = 2005-10-15t13:12:11-0700
left after parsing: "-0700".
t = 2005-10-15t13:12:11z

i understand why this: %q format documented "output only", can't find way read string?! how should this?

the sad state of affairs is, yes, limitation

some new flags have been added, , others overridden. input system supports specific flags, therefore, not flags work output work input (we working correct situation).

meanwhile, might able leverage boost locale's input/output facilities: http://www.boost.org/doc/libs/1_55_0/libs/locale/doc/html/group__manipulators.html


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -