This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

strptime vs C locale vs other locale - test case attached


Hello,

The attached test [1] on glibc 2.8 shows that C locale date isn't parsed
correctly after chaning LC_TIME. glibc strptime has AFAIK gnu extension
that makes strptime() parsing C locate dates correctly even
if LC_TIME is set to some other locale, correct?

glibc 2.7, 2.8

$ ./a.out
DEBUG: Parsed as 00-00-00
DEBUG: Parsed as 23-00-108
DEBUG: Parsed as 23-00-108
DEBUG: Parsed as 23-00-108

glibc 2.3.6

$ ./a.out
DEBUG: Parsed as 23-00-108
DEBUG: Parsed as 23-00-108
DEBUG: Parsed as 23-00-108
DEBUG: Parsed as 23-00-108

(don't have machine with other glibc versions to test)

1. by patrys/pld-linux.org

#define _GNU_SOURCE 1
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <locale.h>

int main()
{
  char *date = "Mon Jan 23 14:01:57 +0000 2008";
  struct tm tmp;
  if (setlocale(LC_TIME, "pl_PL") == NULL)
          printf("setlocale() == NULL\n");
  memset (&tmp, 0, sizeof (tmp));
  strptime (date, "%a %b %d %T %z %Y", &tmp);
  printf ("DEBUG: Parsed as %02d-%02d-%02d\n", tmp.tm_mday, tmp.tm_mon, 
tmp.tm_year);
  memset (&tmp, 0, sizeof (tmp));
  strptime (date, "Mon %b %d %T %z %Y", &tmp);
  printf ("DEBUG: Parsed as %02d-%02d-%02d\n", tmp.tm_mday, tmp.tm_mon, 
tmp.tm_year);
  setlocale(LC_TIME, "C");
  memset (&tmp, 0, sizeof (tmp));
  strptime (date, "%a %b %d %T %z %Y", &tmp);
  printf ("DEBUG: Parsed as %02d-%02d-%02d\n", tmp.tm_mday, tmp.tm_mon, 
tmp.tm_year);
  memset (&tmp, 0, sizeof (tmp));
  strptime (date, "Mon %b %d %T %z %Y", &tmp);
  printf ("DEBUG: Parsed as %02d-%02d-%02d\n", tmp.tm_mday, tmp.tm_mon, 
tmp.tm_year);
}

-- 
Arkadiusz MiÅkiewicz        PLD/Linux Team
arekm / maven.pl            http://ftp.pld-linux.org/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]