Re: [Cppcms-users] date_time and as::time_zone question
Brought to you by:
artyom-beilis
From: Pavel K. <un...@fu...> - 2011-03-18 18:35:01
|
hi, it's locale problem. set std::locale::global() for newly created streams and use imbue() to affect std::cout. int main() { std::locale::global( booster::locale::generator().generate( "" ) ); std::string tz = "Canada/Eastern"; booster::locale::date_time dt; std::istringstream is("1999-04-22 12:13:14"); is >> booster::locale::as::ftime( "%Y-%m-%d %H:%M:%S" ) >> dt; std::cout.imbue( std::locale() ); std::cout << booster::locale::as::time_zone(tz) << booster::locale::as::ftime( "%Y-%m-%d %H:%M:%S" ) << dt << std::endl; } pavel. On Friday 18 March 2011, Heiko Weber wrote: > Hi Artyom, > > first, thanks for the work, I am really impressed about what I've > discovered so far ! > > I am just trying to figure out what parts of "boost" are still accessable > with booster ... so, maybe the following is just not working by intention? > I hope you can give me some enlightment ;) > > This one results in an exception: > > terminate called after throwing an instance of 'std::bad_cast' > what(): std::bad_cast > Abort trap > > --- > > #include <booster/locale/date_time.h> > #include <booster/locale/formatting.h> > #include <booster/locale/generator.h> > #include <booster/locale/localization_backend.h> > #include <iostream> > #include <sstream> > > int main() { > > booster::locale::localization_backend_manager my = > booster::locale::localization_backend_manager::global(); // Get global > backend > > my.select("icu"); > > std::string tz = "Canada/Eastern"; > booster::locale::date_time dt; > > std::istringstream is("1999-04-22 12:13:14"); > is >> booster::locale::as::ftime( "%Y-%m-%d %H:%M:%S" ) >> dt; > std::cout << booster::locale::as::time_zone(tz) << > booster::locale::as::ftime( "%Y-%m-%d %H:%M:%S" ) << dt << std::endl; } > > I also also tried it without the backend select, but same result. The throw > happens at the constructor of dt, shouldn't it work without setting up a > calendar/locale first ? > > Thanks in advance. > Heiko |