datatype.js revision 185ffe6feb5b848dd17fdcb7c953b60cc63b1e7f
1127N/A * @submodule datatype-number-parse 1127N/A * Converts data to type Number. 1127N/A * @param data {String | Number | Boolean} Data to convert. The following 1127N/A * values return as null: null, undefined, NaN, "". 1127N/A * @return {Number} A number, or null. 1127N/A * @submodule datatype-number 1127N/A * @submodule datatype-number-format 1127N/A * DataType.Number provides a set of utility functions to operate against Number objects. 1127N/A * Takes a Number and formats to string for display to user. 1127N/A * @param data {Number} Number. 1127N/A * @param config {Object} (Optional) Optional configuration values: 1127N/A * <dd>String prepended before each number, like a currency designator "$"</dd> 1127N/A * <dt>decimalPlaces {Number}</dd> 1127N/A * <dd>Number of decimal places to round. Must be a number 0 to 20.</dd> 1127N/A * <dt>decimalSeparator {String}</dd> 1127N/A * <dd>Decimal separator</dd> 1127N/A * <dt>thousandsSeparator {String}</dd> 1127N/A * <dd>Thousands separator</dd> 1127N/A * <dd>String appended after each number, like " items" (note the space)</dd> 1127N/A * @return {String} Formatted number for display. Note, the following values 1127N/A * return as "": null, undefined, NaN, "". // Round to the correct decimal place // Add the thousands separator // Find the dot or where it would be // Start with the dot and everything to the right // Working left, every third time add a separator, every time add a digit // Not a Number, just return as string YUI.
add(
'datatype-number',
function(Y){},
'@VERSION@' ,{
use:[
'datatype-number-parse',
'datatype-number-format']});
YUI.
add(
'datatype-date-parse',
function(Y) {
* Parse number submodule. * @submodule datatype-date-parse * Converts data to type Date. * @param data {String | Number} Data to convert. Values supported by the Date constructor are supported. * @return {Date} A Date, or null. YUI.
add(
'datatype-date-format',
function(Y) {
* The DataType Utility provides type-conversion and string-formatting * convenience methods for various JavaScript object types. * @submodule datatype-date * Format date submodule implements strftime formatters for javascript based on the * Open Group specification defined at * This implementation does not include modified conversion specifiers (i.e., Ex and Ox) * @submodule datatype-date-format * DataType.Date provides a set of utility functions to operate against Date objects. * Pad a number with leading spaces, zeroes or something else * @param x {Number} The number to be padded * @param pad {String} The character to pad the number with * @param r {Number} (optional) The base of the pad, eg, 10 implies to two digits, 100 implies to 3 digits. if(
typeof r ===
"undefined")
for( ;
parseInt(x,
10)<r && r>
1; r/=
10) {
a:
function (d, l) {
return l.a[d.
getDay()]; },
A:
function (d, l) {
return l.A[d.
getDay()]; },
b:
function (d, l) {
return l.b[d.
getMonth()]; },
B:
function (d, l) {
return l.B[d.
getMonth()]; },
}
else if(W===
0 && V>=
52) {
I:
function (d) {
var I=d.
getHours()%
12;
return xPad(I===
0?
12:I,
0); },
l:
function (d) {
var I=d.
getHours()%
12;
return xPad(I===
0?
12:I,
" "); },
p:
function (d, l) {
return l.p[d.
getHours() >=
12 ?
1 :
0 ]; },
P:
function (d, l) {
return l.P[d.
getHours() >=
12 ?
1 :
0 ]; },
// First week is 01 and not 00 as in the case of %U and %W, // so we add 1 to the final result except if day 1 of the year // is a Monday (then %W returns 01). // We also need to subtract 1 if the day 1 of the year is // Friday-Sunday, so the resulting equation becomes: return (o>
0?
"-":
"+") + H + M;
"%":
function (d) {
return "%"; }
//"+": "%a %b %e %T %Z %Y" * Takes a native JavaScript Date and formats it as a string for display to user. * @param oDate {Date} Date. * @param oConfig {Object} (Optional) Object literal of configuration values: * <dt>format {String} (Optional)</dt> * Any strftime string is supported, such as "%I:%M:%S %p". strftime has several format specifiers defined by the Open group at * This javascript implementation supports all the PHP specifiers and a few more. The full list is below. * If not specified, it defaults to the ISO 8601 standard date format: %Y-%m-%d. * This may be overridden by the deprecated Y.config.dateFormat property. * <dt>%a</dt> <dd>abbreviated weekday name according to the current locale</dd> * <dt>%A</dt> <dd>full weekday name according to the current locale</dd> * <dt>%b</dt> <dd>abbreviated month name according to the current locale</dd> * <dt>%B</dt> <dd>full month name according to the current locale</dd> * <dt>%c</dt> <dd>preferred date and time representation for the current locale</dd> * <dt>%C</dt> <dd>century number (the year divided by 100 and truncated to an integer, range 00 to 99)</dd> * <dt>%d</dt> <dd>day of the month as a decimal number (range 01 to 31)</dd> * <dt>%D</dt> <dd>same as %m/%d/%y</dd> * <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> * <dt>%F</dt> <dd>same as %Y-%m-%d (ISO 8601 date format)</dd> * <dt>%g</dt> <dd>like %G, but without the century</dd> * <dt>%G</dt> <dd>The 4-digit year corresponding to the ISO week number</dd> * <dt>%h</dt> <dd>same as %b</dd> * <dt>%H</dt> <dd>hour as a decimal number using a 24-hour clock (range 00 to 23)</dd> * <dt>%I</dt> <dd>hour as a decimal number using a 12-hour clock (range 01 to 12)</dd> * <dt>%j</dt> <dd>day of the year as a decimal number (range 001 to 366)</dd> * <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> * <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> * <dt>%m</dt> <dd>month as a decimal number (range 01 to 12)</dd> * <dt>%M</dt> <dd>minute as a decimal number</dd> * <dt>%n</dt> <dd>newline character</dd> * <dt>%p</dt> <dd>either "AM" or "PM" according to the given time value, or the corresponding strings for the current locale</dd> * <dt>%P</dt> <dd>like %p, but lower case</dd> * <dt>%r</dt> <dd>time in a.m. and p.m. notation equal to %I:%M:%S %p</dd> * <dt>%R</dt> <dd>time in 24 hour notation equal to %H:%M</dd> * <dt>%s</dt> <dd>number of seconds since the Epoch, ie, since 1970-01-01 00:00:00 UTC</dd> * <dt>%S</dt> <dd>second as a decimal number</dd> * <dt>%t</dt> <dd>tab character</dd> * <dt>%T</dt> <dd>current time, equal to %H:%M:%S</dd> * <dt>%u</dt> <dd>weekday as a decimal number [1,7], with 1 representing Monday</dd> * <dt>%U</dt> <dd>week number of the current year as a decimal number, starting with the * first Sunday as the first day of the first week</dd> * <dt>%V</dt> <dd>The ISO 8601:1988 week number of the current year as a decimal number, * range 01 to 53, where week 1 is the first week that has at least 4 days * in the current year, and with Monday as the first day of the week.</dd> * <dt>%w</dt> <dd>day of the week as a decimal, Sunday being 0</dd> * <dt>%W</dt> <dd>week number of the current year as a decimal number, starting with the * first Monday as the first day of the first week</dd> * <dt>%x</dt> <dd>preferred date representation for the current locale without the time</dd> * <dt>%X</dt> <dd>preferred time representation for the current locale without the date</dd> * <dt>%y</dt> <dd>year as a decimal number without a century (range 00 to 99)</dd> * <dt>%Y</dt> <dd>year as a decimal number including the century</dd> * <dt>%z</dt> <dd>numerical time zone representation</dd> * <dt>%Z</dt> <dd>time zone name or abbreviation</dd> * <dt>%%</dt> <dd>a literal "%" character</dd> * <dt>locale {String} (Deprecated, optional)</dt> * <b>Deprecated - use Y.config.lang instead, which provides access to a much larger set of built-in languages.</b> * The locale to use when displaying days of week, months of the year, and other locale specific * strings. If not specified, this defaults to "en" (though this may be overridden by the deprecated Y.config.locale). * The following locales are built in: * <dd>British English</dd> * <dd>Australian English (identical to British English)</dd> * More locales may be added by subclassing of the deprecated Y.DataType.Date.Locale["en"]. * See Y.DataType.Date.Locale for more information. * @return {String} Formatted date for display. // Y.config.dateFormat is deprecated - remove from YUI 3.2 // compatMode supports deprecated features - remove from YUI 3.2 // Make sure we have a definition for the requested locale, or default to en. case "string":
// string => built in date function case "function":
// function => our own function case "array":
// built in function with padding }
// no break; (fall through to default:) // Y.config.dateFormat is deprecated - remove from YUI 3.2 // First replace aggregates (run in a loop because an agg may be made up of other aggs) // Now replace formats (do not run in a loop otherwise %%a will be replace with the value of %a) * 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: * <li>Find an existing locale that matches closely with your needs</li> * <li>Use this as your base class. Use Y.DataType.Date.Locale["en"] if nothing * <li>Create your own class as an extension of the base class using * Y.merge, and add your own localisations where needed.</li> * 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: * <li>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", * <li>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"], { * 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" }); * mardi, 22 avril == 22.04.2008 * Y.DataType.Date.format(d, {format: "%A, %d %B == %x", locale: "fr-CA" }); * mardi, 22 avril == 2008-04-22 * @class DataType.Date.Locale * @deprecated - use Y.config.lang to request one of many built-in languages instead. a: [
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"],
A: [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"],
b: [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"],
B: [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"],
c:
"%a %d %b %Y %I:%M:%S %p %Z",
},
'@VERSION@' ,{
lang:[
'ar',
'ar-JO',
'ca',
'ca-ES',
'da',
'da-DK',
'de',
'de-AT',
'de-DE',
'el',
'el-GR',
'en',
'en-AU',
'en-CA',
'en-GB',
'en-IE',
'en-IN',
'en-JO',
'en-MY',
'en-NZ',
'en-PH',
'en-SG',
'en-US',
'es',
'es-AR',
'es-BO',
'es-CL',
'es-CO',
'es-EC',
'es-ES',
'es-MX',
'es-PE',
'es-PY',
'es-US',
'es-UY',
'es-VE',
'fi',
'fi-FI',
'fr',
'fr-BE',
'fr-CA',
'fr-FR',
'hi',
'hi-IN',
'id',
'id-ID',
'it',
'it-IT',
'ja',
'ja-JP',
'ko',
'ko-KR',
'ms',
'ms-MY',
'nb',
'nb-NO',
'nl',
'nl-BE',
'nl-NL',
'pl',
'pl-PL',
'pt',
'pt-BR',
'ro',
'ro-RO',
'ru',
'ru-RU',
'sv',
'sv-SE',
'th',
'th-TH',
'tr',
'tr-TR',
'vi',
'vi-VN',
'zh-Hans',
'zh-Hans-CN',
'zh-Hant',
'zh-Hant-HK',
'zh-Hant-TW']});
YUI.
add(
'datatype-date',
function(Y){},
'@VERSION@' ,{
use:[
'datatype-date-parse',
'datatype-date-format']});
YUI.
add(
'datatype-xml-parse',
function(Y) {
* @submodule datatype-xml-parse * Converts data to type XMLDocument. * @param data {String} Data to convert. * @return {XMLDoc} XML Document. YUI.
add(
'datatype-xml-format',
function(Y) {
* @submodule datatype-xml-format * @submodule datatype-xml * DataType.XML provides a set of utility functions to operate against XML documents. * Converts data to type XMLDocument. * @param data {XMLDoc} Data to convert. * @return {String} String. YUI.
add(
'datatype-xml',
function(Y){},
'@VERSION@' ,{
use:[
'datatype-xml-parse',
'datatype-xml-format']});
YUI.
add(
'datatype',
function(Y){},
'@VERSION@' ,{
use:[
'datatype-number',
'datatype-date',
'datatype-xml']});