tst_wcsftime.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <features.h>
  4. #include <wchar.h>
  5. #include <locale.h>
  6. #define NUM_OF_DATES 7
  7. #define NUM_OF_LOCALES 3
  8. #define BUF_SIZE 256
  9. int
  10. main (void)
  11. {
  12. wchar_t buf[BUF_SIZE];
  13. struct tm *tp;
  14. time_t time_list[NUM_OF_DATES] = {
  15. 500, 68200000, 694223999,
  16. 694224000, 704900000, 705000000,
  17. 705900000
  18. };
  19. char *locale_list[NUM_OF_LOCALES] = {
  20. "C",
  21. "fr_FR.ISO-8859-1",
  22. "ja_JP.UTF-8"
  23. };
  24. int result = 0, ddd, lll;
  25. size_t n;
  26. for (lll = 0; lll < NUM_OF_LOCALES; lll++) {
  27. printf ("\nUsing locale: %s\n", locale_list[lll]);
  28. char* set = setlocale(LC_ALL, locale_list[lll]);
  29. if (set == NULL) {
  30. printf ("FAILED!\n\n");
  31. continue;
  32. } else
  33. printf ("\n");
  34. for (ddd = 0; ddd < NUM_OF_DATES; ddd++) {
  35. tp = localtime(&time_list[ddd]);
  36. printf ("%ld corresponds to ", time_list[ddd]);
  37. n = wcsftime (buf, sizeof (buf) / sizeof (buf[0]),
  38. L"%H:%M:%S %Y-%m-%d%n", tp);
  39. if (n != 21) {
  40. result = 1;
  41. printf ("FAILED!\n");
  42. }
  43. printf ("%ls", buf);
  44. wcsftime (buf, sizeof (buf) / sizeof (buf[0]),
  45. L"%tor, as %%D %%T: %D %T%n", tp);
  46. printf ("%ls", buf);
  47. wcsftime (buf, sizeof (buf) / sizeof (buf[0]), L"%A (%a)%n", tp);
  48. printf ("The weekday was %ls", buf);
  49. wcsftime (buf, sizeof (buf) / sizeof (buf[0]), L"%B (%b) %Y%n", tp);
  50. /* glibc bug? forgets aigu from french february février
  51. * See s/printf (/wprintf (L/g */
  52. //wprintf (L"Month was %ls", buf);
  53. printf ("Month was %ls", buf);
  54. }
  55. }
  56. return result;
  57. }