std.date proposal + locales

kris foo at bar.com
Wed Mar 29 10:04:36 PST 2006


John C wrote:
>>So, what date is: 01/02/03
>>
>>1) in an Arab context
>>2) in an American context
>>3) in a British context
>>4) in an CJK context
>>5) in a Frensh context
>>6) in a German context
>>7) in an Israeli context
> 
> 
> Ah, a trap. I could say for most of them it's 1 February 2003, but you can't 
> rely on that being so. Really, it's for a good locale library to answer. 


Anyone doing locale-specific formatting should take a look at what John 
created over here: http://svn.dsource.org/projects/mango/trunk/mango/locale/

... all kind of handy formatting, including a variety of Calendar types. 
Here's a snip from the docs:

---------------------

// Format with the user's current culture (eg, en-GB).
Formatter.format("General: {0} Hexadecimal: 0x{0:x4} Numeric: {0:N}", 1000);
// -> General: 1000 Hexadecimal: 0x03e8 Numeric: 1,000.00

// Format using a custom display format, substituting groups with those 
appropriate for Germany.
Formatter.format(Culture.getCulture("de-DE"), "{0:#,#}", 12345678);
// -> 12.345.678

// Format as a monetary value appropriate for Spain.
Formatter.format(Culture.getCulture("es-ES"), "{0:C}", 59.99);
// -> 59,99 €

// Format today's date as appropriate for France.
Formatter.format(Culture.getCulture("fr-FR"), "{0:D}", DateTime.today);
// -> vendredi 3 mars 2006

---------------------


If that's not sufficient for some, there's always the venerable ICU 
wrappers.

- Kris



More information about the Digitalmars-d-announce mailing list