API Docs for: 3.5.1
Show:

DataType.Date.Locale Class

Deprecated: - use Y.config.lang to request one of many built-in languages instead.

The Date.Locale class is a container for all localised date strings used by Y.DataType.Date. It is used internally, but may be extended to provide new date localisations.

To create your own Locale, follow these steps:

  1. Find an existing locale that matches closely with your needs
  2. Use this as your base class. Use Y.DataType.Date.Locale["en"] if nothing matches.
  3. Create your own class as an extension of the base class using Y.merge, and add your own localisations where needed.

See the Y.DataType.Date.Locale["en-US"] and Y.DataType.Date.Locale["en-GB"] classes which extend Y.DataType.Date.Locale["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 Y.DataType.Date.Locale["en"] as the base, and extend it:
         Y.DataType.Date.Locale["fr"] = Y.merge(Y.DataType.Date.Locale["en"], {
             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:
         Y.DataType.Date.Locale["fr-CA"] = Y.merge(Y.DataType.Date.Locale["fr"], {
             x: "%Y-%m-%d"
         });
      

With that, you can use your new locales:

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

will return:

   mardi, 22 avril == 22.04.2008

And

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

Will return:

  mardi, 22 avril == 2008-04-22

Item Index