datatype.js revision 7b5f0d3729d3d64194ad355fc8b82402d5bf92db
0N/AYUI.add('datatype-number-parse', function(Y) {
4597N/A
1008N/A/**
1008N/A * The DataType utility provides a set of utility functions to operate on native
1008N/A * JavaScript data types.
1008N/A *
2362N/A * @module datatype
1008N/A */
2362N/Avar LANG = Y.Lang;
1008N/A
1008N/A/**
1008N/A * Parse number submodule.
1008N/A *
1008N/A * @class DataType.Number
1008N/A * @submodule datatype-number-format
1008N/A * @static
1008N/A */
1008N/AY.mix(Y.namespace("DataType.Number"), {
1008N/A /**
1008N/A * Converts data to type Number.
2362N/A *
2362N/A * @method parse
2362N/A * @param data {String | Number | Boolean} Data to convert. The following
1008N/A * values return as null: null, undefined, NaN, "".
1008N/A * @return {Number} A number, or null.
1008N/A * @static
1008N/A */
0N/A parse: function(data) {
0N/A var number = (data === null) ? data : +data;
1821N/A if(LANG.isNumber(number)) {
1821N/A return number;
1821N/A }
1821N/A else {
1821N/A return null;
1821N/A }
1821N/A }
1821N/A});
1821N/A
1821N/A// Add Parsers shortcut
2391N/AY.namespace("Parsers").number = Y.DataType.Number.parse;
1821N/A
1821N/A
2391N/A
1821N/A}, '@VERSION@' );
1821N/A
1821N/AYUI.add('datatype-number-format', function(Y) {
2391N/A
1821N/A/**
1821N/A * The DataType utility provides a set of utility functions to operate on native
1821N/A * JavaScript data types.
1821N/A *
1821N/A * @module datatype
1821N/A */
1821N/Avar LANG = Y.Lang;
1821N/A
1821N/A/**
1821N/A * Format number submodule.
1821N/A *
1821N/A * @class DataType.Number
1008N/A * @submodule datatype-number-format
1008N/A * @static
1821N/A */
1008N/AY.mix(Y.namespace("DataType.Number"), {
1008N/A /**
1008N/A * Takes a Number and formats to string for display to user.
1008N/A *
1008N/A * @method format
1821N/A * @param data {Number} Number.
1821N/A * @param config {Object} (Optional) Optional configuration values:
1821N/A * <dl>
1821N/A * <dt>prefix {String}</dd>
1821N/A * <dd>String prepended before each number, like a currency designator "$"</dd>
1821N/A * <dt>decimalPlaces {Number}</dd>
1821N/A * <dd>Number of decimal places to round. Must be a number 0 to 20.</dd>
1821N/A * <dt>decimalSeparator {String}</dd>
2228N/A * <dd>Decimal separator</dd>
2228N/A * <dt>thousandsSeparator {String}</dd>
2228N/A * <dd>Thousands separator</dd>
2228N/A * <dt>suffix {String}</dd>
1821N/A * <dd>String appended after each number, like " items" (note the space)</dd>
0N/A * </dl>
4634N/A * @return {String} Formatted number for display. Note, the following values
4634N/A * return as "": null, undefined, NaN, "".
4634N/A */
4634N/A format: function(data, config) {
4634N/A if(LANG.isNumber(data)) {
4634N/A config = config || {};
4634N/A
4634N/A var isNeg = (data < 0),
4634N/A output = data + "",
2402N/A decPlaces = config.decimalPlaces,
2402N/A decSep = config.decimalSeparator || ".",
2402N/A thouSep = config.thousandsSeparator,
2402N/A decIndex,
2402N/A newOutput, count, i;
2402N/A
2402N/A // Decimal precision
2402N/A if(LANG.isNumber(decPlaces) && (decPlaces >= 0) && (decPlaces <= 20)) {
2402N/A // Round to the correct decimal place
2402N/A output = data.toFixed(decPlaces);
2402N/A }
2402N/A
2402N/A // Decimal separator
2402N/A if(decSep !== "."){
2402N/A output = output.replace(".", decSep);
2402N/A }
2402N/A
2402N/A // Add the thousands separator
2402N/A if(thouSep) {
0N/A // Find the dot or where it would be
0N/A decIndex = output.lastIndexOf(decSep);
1008N/A decIndex = (decIndex > -1) ? decIndex : output.length;
1821N/A // Start with the dot and everything to the right
1821N/A newOutput = output.substring(decIndex);
1821N/A // Working left, every third time add a separator, every time add a digit
2228N/A for (count = 0, i=decIndex; i>0; i--) {
2228N/A if ((count%3 === 0) && (i !== decIndex) && (!isNeg || (i > 1))) {
2228N/A newOutput = thouSep + newOutput;
2228N/A }
2228N/A newOutput = output.charAt(i-1) + newOutput;
2228N/A count++;
2228N/A }
2228N/A output = newOutput;
2228N/A }
2228N/A
2402N/A // Prepend prefix
2402N/A output = (config.prefix) ? config.prefix + output : output;
2402N/A
2402N/A // Append suffix
2402N/A output = (config.suffix) ? output + config.suffix : output;
4634N/A
2402N/A return output;
2402N/A }
2402N/A // Not a Number, just return as string
2402N/A else {
2402N/A return data.toString();
2402N/A }
2402N/A }
2402N/A});
2402N/A
2402N/A
2402N/A
2402N/A}, '@VERSION@' );
2402N/A
2402N/A
2402N/A
2402N/AYUI.add('datatype-number', function(Y){}, '@VERSION@' ,{use:['datatype-number-parse', 'datatype-number-format']});
1821N/A
2228N/A
2228N/AYUI.add('datatype-date', function(Y) {
2228N/A
2228N/A/**
2228N/A * The Date formatter utility implements strftime formatters for javascript based on the
2228N/A * Open Group specification defined at
2228N/A * http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html
2228N/A * This implementation does not include modified conversion specifiers (i.e., Ex and Ox)
2228N/A *
2228N/A * The following format specifiers are supported:
2228N/A *
1821N/A * \copydoc formats
1821N/A *
1821N/A * \par Usage:
2228N/A * This library may be used as follows:
2228N/A * \code
2228N/A * var d = Y.DataType.Date.format(new Date("2009/04/10", { format: "Today is %A, the %d of %B, %Y" });
2228N/A * \endcode
2228N/A *
1821N/A *
2228N/A * @module datatype
1821N/A * @submodule datatype-date
2228N/A * @requires oop
2228N/A * @title DataType Date Formatter Submodule
1821N/A */
2228N/A
1821N/A/**
1821N/A * Pad a number with leading spaces, zeroes or something else
1821N/A * @param x {Number} The number to be padded
1821N/A * @param pad {String} The character to pad the number with
1821N/A * @param r {Number} (optional) The base of the pad, eg, 10 implies to two digits, 100 implies to 3 digits.
1821N/A * @private
1821N/A */
1821N/Avar xPad=function (x, pad, r)
1821N/A{
1821N/A if(typeof r === "undefined")
2228N/A {
1821N/A r=10;
1821N/A }
1821N/A pad = pad.toString();
1821N/A for( ; parseInt(x, 10)<r && r>1; r/=10) {
1821N/A x = pad + x;
1821N/A }
1821N/A return x.toString();
1821N/A};
0N/A
1821N/AY.config.dateFormat = Y.config.dateFormat || "%Y-%m-%d";
1008N/AY.config.locale = Y.config.locale || "en";
0N/A
0N/A/**
2228N/A * Date subclass for the YUI DataType utility.
2228N/A * @class DataType.Date
2228N/A * @requires base
2228N/A * @static
2228N/A */
2228N/Avar Dt = {
0N/A formats: {
1821N/A a: function (d, l) { return l.a[d.getDay()]; },
0N/A A: function (d, l) { return l.A[d.getDay()]; },
1008N/A b: function (d, l) { return l.b[d.getMonth()]; },
1008N/A B: function (d, l) { return l.B[d.getMonth()]; },
1008N/A C: function (d) { return xPad(parseInt(d.getFullYear()/100, 10), 0); },
1008N/A d: ["getDate", "0"],
2228N/A e: ["getDate", " "],
1008N/A g: function (d) { return xPad(parseInt(Dt.formats.G(d)%100, 10), 0); },
2228N/A G: function (d) {
2228N/A var y = d.getFullYear();
0N/A var V = parseInt(Dt.formats.V(d), 10);
1008N/A var W = parseInt(Dt.formats.W(d), 10);
1008N/A
1008N/A if(W > V) {
2228N/A y++;
2228N/A } else if(W===0 && V>=52) {
2228N/A y--;
2228N/A }
2228N/A
2228N/A return y;
2228N/A },
1008N/A H: ["getHours", "0"],
1008N/A I: function (d) { var I=d.getHours()%12; return xPad(I===0?12:I, 0); },
1008N/A j: function (d) {
1008N/A var gmd_1 = new Date("" + d.getFullYear() + "/1/1 GMT");
1008N/A var gmdate = new Date("" + d.getFullYear() + "/" + (d.getMonth()+1) + "/" + d.getDate() + " GMT");
1008N/A var ms = gmdate - gmd_1;
1821N/A var doy = parseInt(ms/60000/60/24, 10)+1;
1008N/A return xPad(doy, 0, 100);
1008N/A },
0N/A k: ["getHours", " "],
0N/A l: function (d) { var I=d.getHours()%12; return xPad(I===0?12:I, " "); },
1008N/A m: function (d) { return xPad(d.getMonth()+1, 0); },
1008N/A M: ["getMinutes", "0"],
1008N/A p: function (d, l) { return l.p[d.getHours() >= 12 ? 1 : 0 ]; },
1008N/A P: function (d, l) { return l.P[d.getHours() >= 12 ? 1 : 0 ]; },
1008N/A s: function (d, l) { return parseInt(d.getTime()/1000, 10); },
0N/A S: ["getSeconds", "0"],
1821N/A u: function (d) { var dow = d.getDay(); return dow===0?7:dow; },
1821N/A U: function (d) {
1821N/A var doy = parseInt(Dt.formats.j(d), 10);
1821N/A var rdow = 6-d.getDay();
1821N/A var woy = parseInt((doy+rdow)/7, 10);
1821N/A return xPad(woy, 0);
1821N/A },
1821N/A V: function (d) {
1821N/A var woy = parseInt(Dt.formats.W(d), 10);
1821N/A var dow1_1 = (new Date("" + d.getFullYear() + "/1/1")).getDay();
1821N/A // First week is 01 and not 00 as in the case of %U and %W,
1821N/A // so we add 1 to the final result except if day 1 of the year
1821N/A // is a Monday (then %W returns 01).
1821N/A // We also need to subtract 1 if the day 1 of the year is
1821N/A // Friday-Sunday, so the resulting equation becomes:
2402N/A var idow = woy + (dow1_1 > 4 || dow1_1 <= 1 ? 0 : 1);
2402N/A if(idow === 53 && (new Date("" + d.getFullYear() + "/12/31")).getDay() < 4)
2402N/A {
2391N/A idow = 1;
2391N/A }
1008N/A else if(idow === 0)
1008N/A {
1008N/A idow = Dt.formats.V(new Date("" + (d.getFullYear()-1) + "/12/31"));
1008N/A }
1008N/A
0N/A return xPad(idow, 0);
1008N/A },
1008N/A w: "getDay",
2391N/A W: function (d) {
1008N/A var doy = parseInt(Dt.formats.j(d), 10);
3866N/A var rdow = 7-Dt.formats.u(d);
1008N/A var woy = parseInt((doy+rdow)/7, 10);
1821N/A return xPad(woy, 0, 10);
1821N/A },
1821N/A y: function (d) { return xPad(d.getFullYear()%100, 0); },
1821N/A Y: "getFullYear",
1821N/A z: function (d) {
1821N/A var o = d.getTimezoneOffset();
1947N/A var H = xPad(parseInt(Math.abs(o/60), 10), 0);
1947N/A var M = xPad(Math.abs(o%60), 0);
1947N/A return (o>0?"-":"+") + H + M;
1947N/A },
1947N/A Z: function (d) {
1947N/A var tz = d.toString().replace(/^.*:\d\d( GMT[+-]\d+)? \(?([A-Za-z ]+)\)?\d*$/, "$2").replace(/[a-z ]/g, "");
1947N/A if(tz.length > 4) {
1947N/A tz = Dt.formats.z(d);
1947N/A }
2017N/A return tz;
1947N/A },
1821N/A "%": function (d) { return "%"; }
1821N/A },
1947N/A
1821N/A aggregates: {
1947N/A c: "locale",
1947N/A D: "%m/%d/%y",
1821N/A F: "%Y-%m-%d",
2017N/A h: "%b",
1821N/A n: "\n",
1821N/A r: "locale",
1821N/A R: "%H:%M",
1821N/A t: "\t",
1821N/A T: "%H:%M:%S",
1821N/A x: "locale",
1821N/A X: "locale"
1821N/A //"+": "%a %b %e %T %Z %Y"
1947N/A },
1821N/A
1821N/A /**
1821N/A * Takes a native JavaScript Date and formats it as a string for display to user.
1947N/A *
1947N/A * @method format
1947N/A * @param oDate {Date} Date.
1821N/A * @param oConfig {Object} (Optional) Object literal of configuration values:
1821N/A * <dl>
1821N/A * <dt>format {String} (Optional)</dt>
1821N/A * <dd>
1821N/A * <p>
2500N/A * Any strftime string is supported, such as "%I:%M:%S %p". strftime has several format specifiers defined by the Open group at
1821N/A * <a href="http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html">http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html</a>
1821N/A * PHP added a few of its own, defined at <a href="http://www.php.net/strftime">http://www.php.net/strftime</a>
1821N/A * </p>
1821N/A * <p>
3866N/A * This javascript implementation supports all the PHP specifiers and a few more. The full list is below.
3866N/A * </p>
3866N/A * <p>
2203N/A * If not specified, it defaults to the ISO8601 standard date format: %Y-%m-%d. This may be overridden by changing Y.config.dateFormat
1947N/A * </p>
1821N/A * <dl>
1008N/A * <dt>%a</dt> <dd>abbreviated weekday name according to the current locale</dd>
1008N/A * <dt>%A</dt> <dd>full weekday name according to the current locale</dd>
0N/A * <dt>%b</dt> <dd>abbreviated month name according to the current locale</dd>
1008N/A * <dt>%B</dt> <dd>full month name according to the current locale</dd>
1008N/A * <dt>%c</dt> <dd>preferred date and time representation for the current locale</dd>
1008N/A * <dt>%C</dt> <dd>century number (the year divided by 100 and truncated to an integer, range 00 to 99)</dd>
0N/A * <dt>%d</dt> <dd>day of the month as a decimal number (range 01 to 31)</dd>
1008N/A * <dt>%D</dt> <dd>same as %m/%d/%y</dd>
1008N/A * <dt>%e</dt> <dd>day of the month as a decimal number, a single digit is preceded by a space (range " 1" to "31")</dd>
1008N/A * <dt>%F</dt> <dd>same as %Y-%m-%d (ISO 8601 date format)</dd>
2500N/A * <dt>%g</dt> <dd>like %G, but without the century</dd>
0N/A * <dt>%G</dt> <dd>The 4-digit year corresponding to the ISO week number</dd>
0N/A * <dt>%h</dt> <dd>same as %b</dd>
0N/A * <dt>%H</dt> <dd>hour as a decimal number using a 24-hour clock (range 00 to 23)</dd>
1008N/A * <dt>%I</dt> <dd>hour as a decimal number using a 12-hour clock (range 01 to 12)</dd>
1008N/A * <dt>%j</dt> <dd>day of the year as a decimal number (range 001 to 366)</dd>
1008N/A * <dt>%k</dt> <dd>hour as a decimal number using a 24-hour clock (range 0 to 23); single digits are preceded by a blank. (See also %H.)</dd>
1008N/A * <dt>%l</dt> <dd>hour as a decimal number using a 12-hour clock (range 1 to 12); single digits are preceded by a blank. (See also %I.) </dd>
1008N/A * <dt>%m</dt> <dd>month as a decimal number (range 01 to 12)</dd>
1008N/A * <dt>%M</dt> <dd>minute as a decimal number</dd>
1008N/A * <dt>%n</dt> <dd>newline character</dd>
1008N/A * <dt>%p</dt> <dd>either "AM" or "PM" according to the given time value, or the corresponding strings for the current locale</dd>
1934N/A * <dt>%P</dt> <dd>like %p, but lower case</dd>
4764N/A * <dt>%r</dt> <dd>time in a.m. and p.m. notation equal to %I:%M:%S %p</dd>
1934N/A * <dt>%R</dt> <dd>time in 24 hour notation equal to %H:%M</dd>
1934N/A * <dt>%s</dt> <dd>number of seconds since the Epoch, ie, since 1970-01-01 00:00:00 UTC</dd>
1934N/A * <dt>%S</dt> <dd>second as a decimal number</dd>
1008N/A * <dt>%t</dt> <dd>tab character</dd>
1008N/A * <dt>%T</dt> <dd>current time, equal to %H:%M:%S</dd>
1008N/A * <dt>%u</dt> <dd>weekday as a decimal number [1,7], with 1 representing Monday</dd>
1008N/A * <dt>%U</dt> <dd>week number of the current year as a decimal number, starting with the
1821N/A * first Sunday as the first day of the first week</dd>
1821N/A * <dt>%V</dt> <dd>The ISO 8601:1988 week number of the current year as a decimal number,
1821N/A * range 01 to 53, where week 1 is the first week that has at least 4 days
4764N/A * in the current year, and with Monday as the first day of the week.</dd>
4764N/A * <dt>%w</dt> <dd>day of the week as a decimal, Sunday being 0</dd>
4764N/A * <dt>%W</dt> <dd>week number of the current year as a decimal number, starting with the
1821N/A * first Monday as the first day of the first week</dd>
4764N/A * <dt>%x</dt> <dd>preferred date representation for the current locale without the time</dd>
4764N/A * <dt>%X</dt> <dd>preferred time representation for the current locale without the date</dd>
4764N/A * <dt>%y</dt> <dd>year as a decimal number without a century (range 00 to 99)</dd>
4764N/A * <dt>%Y</dt> <dd>year as a decimal number including the century</dd>
1821N/A * <dt>%z</dt> <dd>numerical time zone representation</dd>
1821N/A * <dt>%Z</dt> <dd>time zone name or abbreviation</dd>
1821N/A * <dt>%%</dt> <dd>a literal "%" character</dd>
1821N/A * </dl>
1821N/A * </dd>
4764N/A * <dt>locale {String} (Optional)</dt>
4764N/A * <dd>
4764N/A * The locale to use when displaying days of week, months of the year, and other locale specific
4764N/A * strings. If not specified, this defaults to "en" (though this may be overridden by changing Y.config.locale).
1821N/A * The following locales are built in:
1821N/A * <dl>
1934N/A * <dt>en</dt>
1821N/A * <dd>English</dd>
1821N/A * <dt>en-US</dt>
1821N/A * <dd>US English</dd>
1821N/A * <dt>en-GB</dt>
3866N/A * <dd>British English</dd>
1821N/A * <dt>en-AU</dt>
1821N/A * <dd>Australian English (identical to British English)</dd>
3866N/A * </dl>
1821N/A * More locales may be added by subclassing of Y.DataType.Date.Locale["en"].
1934N/A * See Y.DataType.Date.Locale for more information.
2500N/A * </dd>
2228N/A * </dl>
1934N/A * @return {String} Formatted date for display.
1934N/A * @sa Y.DataType.Date.Locale
2228N/A */
1934N/A format : function (oDate, oConfig) {
1934N/A oConfig = oConfig || {};
1821N/A
1821N/A if(!Y.Lang.isDate(oDate)) {
3866N/A return Y.Lang.isValue(oDate) ? oDate : "";
1821N/A }
1821N/A
1821N/A var format = oConfig.format || Y.config.dateFormat,
1821N/A sLocale = oConfig.locale || Y.config.locale;
1821N/A
1008N/A sLocale = sLocale.replace(/_/g, "-");
1008N/A
1934N/A // Make sure we have a definition for the requested locale, or default to en.
1934N/A if(!Dt.Locale[sLocale]) {
1934N/A var tmpLocale = sLocale.replace(/-[a-zA-Z]+$/, "");
1934N/A if(tmpLocale in Dt.Locale) {
4764N/A sLocale = tmpLocale;
4764N/A } else if(Y.config.locale in Dt.Locale) {
4764N/A sLocale = Y.config.locale;
4764N/A } else {
1821N/A sLocale = "en";
1821N/A }
3740N/A }
4764N/A
1821N/A var aLocale = Dt.Locale[sLocale];
1821N/A
2017N/A var replace_aggs = function (m0, m1) {
1821N/A var f = Dt.aggregates[m1];
2017N/A return (f === "locale" ? aLocale[m1] : f);
1821N/A };
1821N/A
1821N/A var replace_formats = function (m0, m1) {
1821N/A var f = Dt.formats[m1];
1821N/A switch(Y.Lang.type(f)) {
1821N/A case "string": // string => built in date function
1821N/A return oDate[f]();
1821N/A case "function": // function => our own function
1821N/A return f.call(oDate, oDate, aLocale);
1821N/A case "array": // built in function with padding
4908N/A if(Y.Lang.type(f[0]) === "string") {
4908N/A return xPad(oDate[f[0]](), f[1]);
1821N/A } // no break; (fall through to default:)
1821N/A default:
1821N/A return m1;
1821N/A }
3740N/A };
3740N/A
1821N/A // First replace aggregates (run in a loop because an agg may be made up of other aggs)
3740N/A while(format.match(/%[cDFhnrRtTxX]/)) {
4764N/A format = format.replace(/%([cDFhnrRtTxX])/g, replace_aggs);
1821N/A }
1821N/A
1821N/A // Now replace formats (do not run in a loop otherwise %%a will be replace with the value of %a)
1821N/A var str = format.replace(/%([aAbBCdegGHIjklmMpPsSuUVwWyYzZ%])/g, replace_formats);
3740N/A
3740N/A replace_aggs = replace_formats = undefined;
3740N/A
1821N/A return str;
2017N/A }
2017N/A};
4764N/A
1821N/AY.namespace("DataType").Date=Dt;
3740N/A
1821N/A/**
1821N/A * The Date.Locale class is a container for all localised date strings
2017N/A * used by Y.DataType.Date. It is used internally, but may be extended
1934N/A * to provide new date localisations.
1934N/A *
1934N/A * To create your own Locale, follow these steps:
4764N/A * <ol>
1821N/A * <li>Find an existing locale that matches closely with your needs</li>
3740N/A * <li>Use this as your base class. Use Y.DataType.Date.Locale["en"] if nothing
4764N/A * matches.</li>
1821N/A * <li>Create your own class as an extension of the base class using
5138N/A * Y.merge, and add your own localisations where needed.</li>
5138N/A * </ol>
5138N/A * See the Y.DataType.Date.Locale["en-US"] and Y.DataType.Date.Locale["en-GB"]
5138N/A * classes which extend Y.DataType.Date.Locale["en"].
5138N/A *
5138N/A * For example, to implement locales for French french and Canadian french,
5138N/A * we would do the following:
5138N/A * <ol>
5138N/A * <li>For French french, we have no existing similar locale, so use
5138N/A * Y.DataType.Date.Locale["en"] as the base, and extend it:
4764N/A * <pre>
1821N/A * Y.DataType.Date.Locale["fr"] = Y.merge(Y.DataType.Date.Locale, {
3740N/A * a: ["dim", "lun", "mar", "mer", "jeu", "ven", "sam"],
4764N/A * A: ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"],
1821N/A * b: ["jan", "f&eacute;v", "mar", "avr", "mai", "jun", "jui", "ao&ucirc;", "sep", "oct", "nov", "d&eacute;c"],
1821N/A * B: ["janvier", "f&eacute;vrier", "mars", "avril", "mai", "juin", "juillet", "ao&ucirc;t", "septembre", "octobre", "novembre", "d&eacute;cembre"],
4764N/A * c: "%a %d %b %Y %T %Z",
1821N/A * p: ["", ""],
3740N/A * P: ["", ""],
1821N/A * x: "%d.%m.%Y",
1821N/A * X: "%T"
1821N/A * });
4764N/A * </pre>
1821N/A * </li>
3740N/A * <li>For Canadian french, we start with French french and change the meaning of \%x:
1821N/A * <pre>
1821N/A * Y.DataType.Date.Locale["fr-CA"] = Y.merge(Y.DataType.Date.Locale["fr"], {
2017N/A * x: "%Y-%m-%d"
1934N/A * });
1934N/A * </pre>
1934N/A * </li>
1821N/A * </ol>
1821N/A *
3740N/A * With that, you can use your new locales:
4764N/A * <pre>
1821N/A * var d = new Date("2008/04/22");
1821N/A * Y.DataType.Date.format(d, { format: "%A, %d %B == %x", locale: "fr" });
1821N/A * </pre>
3740N/A * will return:
4908N/A * <pre>
5892N/A * mardi, 22 avril == 22.04.2008
5892N/A * </pre>
4764N/A * And
1821N/A * <pre>
1821N/A * Y.DataType.Date.format(d, {format: "%A, %d %B == %x", locale: "fr-CA" });
1821N/A * </pre>
3740N/A * Will return:
4764N/A * <pre>
1821N/A * mardi, 22 avril == 2008-04-22
1821N/A * </pre>
1821N/A * @module datatype
3740N/A * @requires oop
4764N/A * @class DataType.Date.Locale
1821N/A */
2546N/Avar YDateEn = {
1821N/A a: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
3740N/A A: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
3887N/A b: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
2402N/A B: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
4764N/A c: "%a %d %b %Y %T %Z",
2017N/A p: ["AM", "PM"],
2546N/A P: ["am", "pm"],
1821N/A r: "%I:%M:%S %p",
4499N/A x: "%d/%m/%y",
4764N/A X: "%T"
1821N/A};
2017N/A
1934N/AY.namespace("DataType.Date.Locale");
1934N/A
1934N/AY.DataType.Date.Locale["en"] = YDateEn;
4499N/A
4499N/AY.DataType.Date.Locale["en-US"] = Y.merge(YDateEn, {
4764N/A c: "%a %d %b %Y %I:%M:%S %p %Z",
4499N/A x: "%m/%d/%Y",
1821N/A X: "%I:%M:%S %p"
1821N/A});
1821N/A
3740N/AY.DataType.Date.Locale["en-GB"] = Y.merge(YDateEn, {
1821N/A r: "%l:%M:%S %P %Z"
1821N/A});
1821N/AY.DataType.Date.Locale["en-AU"] = Y.merge(YDateEn);
1821N/A
3740N/A
4764N/A
1821N/A
1821N/A
1821N/A}, '@VERSION@' );
1821N/A
3740N/AYUI.add('datatype-xml-parse', function(Y) {
5910N/A
2017N/A/**
2017N/A * The DataType utility provides a set of utility functions to operate on native
2017N/A * JavaScript data types.
1821N/A *
3740N/A * @module datatype
4597N/A */
4908N/Avar LANG = Y.Lang;
4597N/A
2402N/A/**
1821N/A * Parse XML submodule.
1821N/A *
2017N/A * @class DataType.XML
1934N/A * @submodule datatype-xml-parse
1934N/A * @static
1934N/A */
4908N/A
4908N/AY.mix(Y.namespace("DataType.XML"), {
4908N/A /**
4908N/A * Converts data to type XMLDocument.
4908N/A *
1821N/A * @method parse
1821N/A * @param data {String} Data to convert.
1821N/A * @return {XMLDoc} XML Document.
4908N/A * @static
4908N/A */
1821N/A parse: function(data) {
1821N/A var xmlDoc = null;
1821N/A if(LANG.isString(data)) {
1821N/A try {
3740N/A if(!LANG.isUndefined(DOMParser)) {
4764N/A xmlDoc = new DOMParser().parseFromString(data, "text/xml");
1821N/A }
2017N/A }
1821N/A catch(e) {
3740N/A try {
4764N/A if(!LANG.isUndefined(ActiveXObject)) {
2017N/A xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
2017N/A xmlDoc.async = false;
2017N/A xmlDoc.loadXML(data);
1821N/A }
3740N/A }
3740N/A catch(ee) {
3740N/A }
2402N/A }
4764N/A }
1821N/A
2017N/A if( (LANG.isNull(xmlDoc)) || (LANG.isNull(xmlDoc.documentElement)) || (xmlDoc.documentElement.nodeName === "parsererror") ) {
1934N/A }
1934N/A
1934N/A return xmlDoc;
1821N/A }
1821N/A});
3740N/A
4764N/A// Add Parsers shortcut
1821N/AY.namespace("Parsers").xml = Y.DataType.XML.parse;
1821N/A
1821N/A
1821N/A
2017N/A}, '@VERSION@' );
2017N/A
2017N/AYUI.add('datatype-xml-format', function(Y) {
1821N/A
1821N/A/**
1821N/A * The DataType utility provides a set of utility functions to operate on native
1821N/A * JavaScript data types.
1821N/A *
1821N/A * @module datatype
1821N/A */
1008N/Avar LANG = Y.Lang;
1008N/A
4764N/A/**
1821N/A * Format XML submodule.
1821N/A *
1821N/A * @class DataType.XML
2020N/A * @submodule datatype-xml-format
2020N/A * @static
2020N/A */
1821N/AY.mix(Y.namespace("DataType.XML"), {
1821N/A /**
1821N/A * Converts data to type XMLDocument.
1821N/A *
1821N/A * @method format
2020N/A * @param data {XMLDoc} Data to convert.
2020N/A * @return {String} String.
2017N/A * @static
2020N/A */
2020N/A format: function(data) {
1821N/A try {
2020N/A if(!LANG.isUndefined(XMLSerializer)) {
2020N/A return (new XMLSerializer()).serializeToString(data);
1008N/A }
1821N/A }
1821N/A catch(e) {
1821N/A if(data.xml) {
1821N/A return data.xml;
1821N/A }
1821N/A else {
1821N/A return data.toString();
1821N/A }
1821N/A }
1821N/A }
1821N/A});
1821N/A
1821N/A
1821N/A
1821N/A
1821N/A}, '@VERSION@' );
1821N/A
1821N/A
1821N/A
1821N/AYUI.add('datatype-xml', function(Y){}, '@VERSION@' ,{use:['datatype-xml-parse', 'datatype-xml-format']});
1947N/A
1008N/A
2402N/A
2402N/A
2402N/AYUI.add('datatype', function(Y){}, '@VERSION@' ,{use:['datatype-number', 'datatype-date', 'datatype-xml']});
2402N/A
2402N/A