qwerti
qwerti

Reputation: 11

Producing locale-specific short dates

When the strftime C function is used under glibc and in combination with, for example, the is_IS locale, the strftime %x format specifier yields a string like "þri 31.des 2013", in other words, it gratuitously includes the weekday and writes the month as a word/abbreviated word. There are other locales that exhibit such behavior.

The way I see it, strftime does not offer anything for users to request a locale-specific "short date" where only digits and separators are used. Therefore, it looks like I would be required to keep a local database of locales and short date formats within my own program, mapping is_IS to "%d.%m.%Y" for example. Are there any additional options to consider? libicu/ICU4C?

Upvotes: 1

Views: 96

Answers (1)

ldav1s
ldav1s

Reputation: 16305

I reproduced your results with:

#include <stdio.h>
#include <time.h>
#include <locale.h>

int
main(void)
{
   char time_buf[128];
   time_t t;
   struct tm *tmp;

   t = time(NULL);
   tmp = localtime(&t);
   setlocale(LC_TIME, "is_IS");
   strftime(time_buf, sizeof(time_buf), "%x", tmp);
   printf("time: `%s'\n", time_buf);

   return 0;
}

To me, this could be a bug (or at least a request to change their current behavior) that should be reported to the glibc maintainers. I don't know what guarantees there are about what you actually get out of locale-specific strftime formats. I would expect something more like the "C" locale's %m/%d/%y output for %x. The "de_DE" locale seems to provide something like this.

Upvotes: 1

Related Questions