API: datasource YAHOO.util.DateLocale (YUI Library)

# Yahoo! UI Library

### DataSource Utility 2.9.0

Yahoo! UI Library > datasource > YAHOO.util.DateLocale
Search:
Filters Show Private Show Protected Show Deprecated

## Class YAHOO.util.DateLocale

The DateLocale class is a container and base class for all localised date strings used by YAHOO.util.Date. It is used internally, but may be extended to provide new date localisations. To create your own DateLocale, follow these steps:

1. Find an existing locale that matches closely with your needs
2. Use this as your base class. Use YAHOO.util.DateLocale if nothing matches.
3. Create your own class as an extension of the base class using YAHOO.lang.merge, and add your own localisations where needed.

See the YAHOO.util.DateLocale['en-US'] and YAHOO.util.DateLocale['en-GB'] classes which extend YAHOO.util.DateLocale['en']. For example, to implement locales for French french and Canadian french, we would do the following:

1. For French french, we have no existing similar locale, so use YAHOO.util.DateLocale as the base, and extend it:

       YAHOO.util.DateLocale['fr'] = YAHOO.lang.merge(YAHOO.util.DateLocale, {
       a: ['dim', 'lun', 'mar', 'mer', 'jeu', 'ven', 'sam'],
       A: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
       b: ['jan', 'fév', 'mar', 'avr', 'mai', 'jun', 'jui', 'aoû', 'sep', 'oct', 'nov', 'déc'],
       B: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
       c: '%a %d %b %Y %T %Z',
       p: ['', ''],
       P: ['', ''],
       x: '%d.%m.%Y',
       X: '%T'
       });

2. For Canadian french, we start with French french and change the meaning of \%x:

       YAHOO.util.DateLocale['fr-CA'] = YAHOO.lang.merge(YAHOO.util.DateLocale['fr'], {
       x: '%Y-%m-%d'
       });

With that, you can use your new locales:

    var d = new Date("2008/04/22");
    YAHOO.util.Date.format(d, {format: "%A, %d %B == %x"}, "fr");

will return:

    mardi, 22 avril == 22.04.2008

And

    YAHOO.util.Date.format(d, {format: "%A, %d %B == %x"}, "fr-CA");

Will return:

    mardi, 22 avril == 2008-04-22

Copyright © 2011 Yahoo! Inc. All rights reserved.