incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Sebor <se...@roguewave.com>
Subject Re: time_get not working in some locales?
Date Wed, 16 Apr 2008 23:28:59 GMT
Mark Brown wrote:
> Hi all!
> 
> I'm having problems with the time_get facet when parsing dates and times
> in some locales such as hi_IN. It works fine in most locales but in a few the
> facet sets failbit without extracting anything. Any ideas what might be going
> wrong?

AFAICT, the facet seems to be failing on the %Z directive. Apparently,
we've never implemented time zone parsing :( Could you please open an
issue for it?

Martin

> 
> Thanks!
> -- Mark
> 
> This fails on Linux:
> 
> #include <stdio.h>
> #include <assert.h>
> #include <locale.h>
> #include <time.h>
> #include <locale>
> #include <sstream>
> 
> int main ()
> {
>     const char* name = "hi_IN";
>     setlocale (LC_ALL, name);
> 
>     const int hour = 10;
>     const int min = 20;
>     const int sec = 30;
> 
>     tm tmb;
>     memset (&tmb, 0, sizeof tmb);
>     tmb.tm_hour = hour;
>     tmb.tm_min = min;
>     tmb.tm_sec = sec;
> 
>     char timestr [80];
>     strftime (timestr, sizeof timestr, "%X", &tmb);
>     puts (timestr);
> 
>     std::locale hindi (name);
>     std::istringstream input (timestr);
>     const std::time_get<char> &tmget =
> std::use_facet<std::time_get<char> >(hindi);
>     memset (&tmb, 0, sizeof tmb);
> 
>     std::istreambuf_iterator<char> start (input);
>     std::istreambuf_iterator<char> end;
> 
>     std::ios::iostate state = std::ios::goodbit;
>     tmget.get_time (start, end, input, state, &tmb);
> 
>     assert (!(state & std::ios::failbit));
>     printf ("time is %d:%d:%d\n", tmb.tm_hour, tmb.tm_min, tmb.tm_sec);
> 
>     assert (hour == tmb.tm_hour && min == tmb.tm_min && sec == tmb.tm_sec);
> }


Mime
View raw message