Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The %x format specifier to the date utility should, according to the man page, use the locale specific date format. However, when I specify the same installed locale and try this on two different machines, I get different formats on each:

On machine 'A':

$ locale -a | grep fr_FR
fr_FR
fr_FR.ISO8859-1
fr_FR.ISO8859-15
fr_FR.UTF-8
$ LC_ALL=fr_FR.UTF-8 date +%x
31.05.2012

On machine 'B':

$ locale -a | grep fr_FR
fr_FR.utf8
$ LC_ALL=fr_FR.UTF-8 date +%x
31/05/2012

I had a look at http://demo.icu-project.org/icu-bin/locexp?d_=en&_=fr_FR, and the section for 'short date' makes it look as if machine 'B' has it right here. Or have I misunderstood something, and in fact the locale settings do not absolutely specify the date format and this sort of variation is to be expected across implementations?

Edit: Hmm.. no takers... Would it be more interesting if I said that machine 'A' is OS X Lion and machine 'B' is Ubuntu 12.04, both of which it would seem reasonable to expect to have correct internationalization/localization settings?

share|improve this question

migrated from stackoverflow.com Jun 3 '12 at 23:40

This question came from our site for professional and enthusiast programmers.

1 Answer 1

up vote 2 down vote accepted

The locale settings are implementation-dependent. Even the locale names aren't guaranteed, though most modern unices do use xx_YY and xx_YY.charset. You can't be sure to expect the same results on different machines, except in the C and POSIX locales.


As a Frenchman, I'll say that B is right and A is wrong. Dots are not used to separate dates in France. (They may be used in other French-speaking countries; perhaps fr_CH should have dots.)

share|improve this answer
    
Thank you for the reply (and the migration?). I can understand that the name by which a locale is selected might reasonably vary across implementations. I'm surprised to hear though that the interpretation can too. Isn't the whole point of a locale to specify how these things (dates, currencies, times) etc. are to be presented? It seems odd that they could reasonably vary across implementations, and your opinion that 'A is wrong' seems to support that on some level. Is there no external standard or reference against which an implementation can be compared to evaluate its correctness? –  acm Jun 4 '12 at 17:42
    
@acm POSIX is the basic standard of unix-like systems, but it only specifies what happens in the POSIX (= C) locale. I'm not aware of any organization that pretends to standardize locales in C- or unix-based programs; locale settings are typically designed for human consumption, so there is no real need for standardization. It would be far more useful to have standard locale names (which the xx_YY format mostly is), so that we could confidently write LANG=fr_FR and have a French-speaking program. –  Gilles Jun 4 '12 at 17:59
    
How frustrating. Thank you for your help though. FWIW, my motivation here is that I am trying to get the libc++ unit tests running and passing on linux. Several of the locale related tests are failing on that platform due to variations like the one above. I had hoped that the problem was with the underlying platform, but it seems the tests are relying on behavior that cannot be safely relied upon. –  acm Jun 4 '12 at 18:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.