Re: [Cppcms-users] booster::date_time parsing
Brought to you by:
artyom-beilis
From: Artyom <art...@ya...> - 2011-03-16 21:54:53
|
> >From: Pavel Kropitz <un...@fu...> >Subject: [Cppcms-users] booster::date_time parsing > > >hello Artyom, > > >first of all, great work ;). combination your framework together with mongodb >and graphicsmagick is amazingly _fast_ and pleasure to use. > > Thanks, I'm glad to hear. > >i have 2 questions about booster::date_time / timezone: > > >1) should parsing handle time before unix era (1970...)? example: > Yes, however you must use ICU backend. All other backends do not support date parsings. http://cppcms.sourceforge.net/boost_locale/html/using_localization_backends.html > >std::string tz = "Europe/Prague"; Note you can use this: http://cppcms.sourceforge.net/boost_locale/html/namespaceboost_1_1locale_1_1time__zone.html To set global time zone. Also you can set timezone independently on stream using as::time_zone manipulator. >booster::locale::calendar cal( context().locale(), tz ); >booster::locale::date_time dt( cal ); > > >std::stringstream ss; >ss.imbue( cal.get_locale() ); > > >ss << "1955-07-21 07:21:07"; // produce 1969-01-01 01:00:00 >//ss << "1985-07-21 07:21:07"; // works as expected > > >ss >> booster::locale::as::ftime( "%Y-%m-%d %H:%M:%S" ) >> dt; >std::cout.imbue( cal.get_locale() ); >std::cout << booster::locale::as::ftime( "%Y-%m-%d %H:%M:%S" ) << dt << >std::endl; > It seems that you need to update the ICU version. I've tested this code (actually boost not booster, but it is the same): #include <boost/locale.hpp> #include <iostream> int main() { std::locale::global(boost::locale::generator().generate("")); std::stringstream s; time_t d; s.str("1955-07-21 07:21:07"); s >> boost::locale::as::ftime("%Y-%m-%d %H:%M:%S") >> d; std::cout.imbue(std::locale()); std::cout << s.str() << std::endl; std::cout << boost::locale::as::ftime("%Y-%m-%d %H:%M:%S") << d << std::endl; } It hadn't work for icu 3.8 (gave a year 1970) but works without problems for icu-4.4 and 4.6, So it seems like ICU issue. (They have bugs as well :-( ) It is fairly simple to compile latest ICU version. > >booster::locale::date_time dt2( cal ); >dt2 -= 50 * booster::locale::period::year; // works as expected >// 1961-03-16 ... >std::cout << booster::locale::as::ftime( "%Y-%m-%d %H:%M:%S" ) << dt2 << >std::endl; > Note date_time object is just a number that is written to stream. See: http://cppcms.sourceforge.net/boost_locale/html/dates_times_timezones.html > >2) is there a way how to obtain all available timezones? currenty i use > icu::TimeZone::createEnumeration() directly. > Currently, there is no such option. Artyom P.S.: Note I use use in the code and documentation boost namespace but it is same code placed in booster namespace for CppCMS. The localization part is actually under review for inclusion in Boost. |