Ticket #187: strftime_test.c

File strftime_test.c, 721 bytes (added by guest, 17 years ago)

Test for strftime with a few locales that came to mind

Line 
1#include <stdio.h>
2#include <locale.h>
3#include <time.h>
4
5int main(void)
6{
7  size_t result;
8  struct tm a;
9  char buf[100];
10  int buflen = 100, i;
11  char *fmt = "%c";
12  char *tryLocales[] = { "en_US", "de_DE", "en_GB", "pl_PL", "cz_CZ", "sk_SK", "fi_FI", "hu_HU", "es_ES" };
13
14  memset(&a, 0, sizeof(struct tm));
15
16  a.tm_sec = 0;
17  a.tm_min = 59;
18  a.tm_hour = 20;
19  a.tm_mday = 17;
20  a.tm_mon = 9;
21  a.tm_wday = 3;
22  a.tm_year = 2007 - 1900;
23  a.tm_yday = 289;
24  a.tm_isdst = 1;
25
26  for (i = 0; i < 9; i++) {
27    setlocale(LC_ALL, tryLocales[i]);
28    result = strftime(buf, buflen, fmt, &a);
29    printf("tryLocale=%s: buf=%s (result=%d)\n", tryLocales[i], buf, result);
30  }
31
32  return 0;
33}