-<html>\r
-<head>\r
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> \r
- <title>The source code</title>\r
- <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
- <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
-</head>\r
-<body onload="prettyPrint();">\r
- <pre class="prettyprint lang-js"><div id="cls-Date"></div>/**
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <title>The source code</title>
+ <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
+ <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
+</head>
+<body onload="prettyPrint();">
+ <pre class="prettyprint lang-js">/*!
+ * Ext JS Library 3.3.0
+ * Copyright(c) 2006-2010 Ext JS, Inc.
+ * licensing@extjs.com
+ * http://www.extjs.com/license
+ */
+<div id="cls-Date"></div>/**
* @class Date
*
* The date parsing and formatting syntax contains a subset of
Date.parseCodes[character] = p; // reassign function result to prevent repeated execution
}
- return p? Ext.applyIf({
- c: p.c? xf(p.c, currentGroup || "{0}") : p.c
+ return p ? Ext.applyIf({
+ c: p.c ? xf(p.c, currentGroup || "{0}") : p.c
}, p) : {
g:0,
c:null,
s:Ext.escapeRe(character) // treat unrecognised characters as literals
- }
-}
+ };
+};
// private shorthand for Date.formatCodeToRegex since we'll be using it fairly often
var $f = Date.formatCodeToRegex;
* may be used as a format string to {@link #format}. Example:</p><pre><code>
Date.formatFunctions['x-date-format'] = myDateFormatter;
</code></pre>
- * <p>A formatting function should return a string repesentation of the passed Date object:<div class="mdetail-params"><ul>
+ * <p>A formatting function should return a string representation of the passed Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
* <li><code>date</code> : Date<div class="sub-desc">The Date to format.</div></li>
* </ul></div></p>
* <p>To enable date strings to also be <i>parsed</i> according to that format, a corresponding
t: "this.getDaysInMonth()",
L: "(this.isLeapYear() ? 1 : 0)",
o: "(this.getFullYear() + (this.getWeekOfYear() == 1 && this.getMonth() > 0 ? +1 : (this.getWeekOfYear() >= 52 && this.getMonth() < 11 ? -1 : 0)))",
- Y: "this.getFullYear()",
+ Y: "String.leftPad(this.getFullYear(), 4, '0')",
y: "('' + this.getFullYear()).substring(2, 4)",
a: "(this.getHours() < 12 ? 'am' : 'pm')",
A: "(this.getHours() < 12 ? 'AM' : 'PM')",
s = s || 0;
ms = ms || 0;
- var dt = new Date(y, m - 1, d, h, i, s, ms);
+ // Special handling for year < 100
+ var dt = new Date(y < 100 ? 100 : y, m - 1, d, h, i, s, ms).add(Date.YEAR, y < 100 ? y - 100 : 0);
return y == dt.getFullYear() &&
m == dt.getMonth() + 1 &&
special = false;
code.push("'" + String.escape(ch) + "'");
} else {
- code.push(Date.getFormatCode(ch))
+ code.push(Date.getFormatCode(ch));
}
}
Date.formatFunctions[format] = new Function("return " + code.join('+'));
"dt = (new Date()).clearTime();",
// date calculations (note: these calculations create a dependency on Ext.num())
- "y = y >= 0? y : Ext.num(def.y, dt.getFullYear());",
- "m = m >= 0? m : Ext.num(def.m - 1, dt.getMonth());",
- "d = d >= 0? d : Ext.num(def.d, dt.getDate());",
+ "y = Ext.num(y, Ext.num(def.y, dt.getFullYear()));",
+ "m = Ext.num(m, Ext.num(def.m - 1, dt.getMonth()));",
+ "d = Ext.num(d, Ext.num(def.d, dt.getDate()));",
// time calculations (note: these calculations create a dependency on Ext.num())
- "h = h || Ext.num(def.h, dt.getHours());",
- "i = i || Ext.num(def.i, dt.getMinutes());",
- "s = s || Ext.num(def.s, dt.getSeconds());",
- "ms = ms || Ext.num(def.ms, dt.getMilliseconds());",
+ "h = Ext.num(h, Ext.num(def.h, dt.getHours()));",
+ "i = Ext.num(i, Ext.num(def.i, dt.getMinutes()));",
+ "s = Ext.num(s, Ext.num(def.s, dt.getSeconds()));",
+ "ms = Ext.num(ms, Ext.num(def.ms, dt.getMilliseconds()));",
"if(z >= 0 && y >= 0){",
// both the year and zero-based day of year are defined and >= 0.
// these 2 values alone provide sufficient info to create a full date object
// create Date object representing January 1st for the given year
- "v = new Date(y, 0, 1, h, i, s, ms);",
+ // handle years < 100 appropriately
+ "v = new Date(y < 100 ? 100 : y, 0, 1, h, i, s, ms).add(Date.YEAR, y < 100 ? y - 100 : 0);",
// then add day of year, checking for Date "rollover" if necessary
"v = !strict? v : (strict === true && (z <= 364 || (v.isLeapYear() && z <= 365))? v.add(Date.DAY, z) : null);",
"v = null;", // invalid date, so return null
"}else{",
// plain old Date object
- "v = new Date(y, m, d, h, i, s, ms);",
+ // handle years < 100 properly
+ "v = new Date(y < 100 ? 100 : y, m, d, h, i, s, ms).add(Date.YEAR, y < 100 ? y - 100 : 0);",
"}",
"}",
"}",
}
}
- Date.parseRegexes[regexNum] = new RegExp("^" + regex.join('') + "$", "i");
+ Date.parseRegexes[regexNum] = new RegExp("^" + regex.join('') + "$", 'i');
Date.parseFunctions[format] = new Function("input", "strict", xf(code, regexNum, calc.join('')));
- }
+ };
}(),
// private
g:0,
c:null,
s:"(?:" + a.join("|") +")"
- }
+ };
},
l: function() {
return {
g:0,
c:null,
s:"(?:" + Date.dayNames.join("|") + ")"
- }
+ };
},
N: {
g:0,
g:1,
c:"m = parseInt(Date.getMonthNumber(results[{0}]), 10);\n", // get localised month number
s:"(" + Date.monthNames.join("|") + ")"
- }
+ };
},
M: function() {
for (var a = [], i = 0; i < 12; a.push(Date.getShortMonthName(i)), ++i); // get localised short month names
+ "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n", // 2-digit year
s:"(\\d{1,2})"
},
+ <div id="prop-Date-a"></div>/**
+ * In the am/pm parsing routines, we allow both upper and lower case
+ * even though it doesn't exactly match the spec. It gives much more flexibility
+ * in being able to specify case insensitive regexes.
+ */
a: {
g:1,
- c:"if (results[{0}] == 'am') {\n"
+ c:"if (/(am)/i.test(results[{0}])) {\n"
+ "if (!h || h == 12) { h = 0; }\n"
+ "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
- s:"(am|pm)"
+ s:"(am|pm|AM|PM)"
},
A: {
g:1,
- c:"if (results[{0}] == 'AM') {\n"
+ c:"if (/(am)/i.test(results[{0}])) {\n"
+ "if (!h || h == 12) { h = 0; }\n"
+ "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
- s:"(AM|PM)"
+ s:"(AM|PM|am|pm)"
},
g: function() {
return $f("G");
")?",
")?"
].join("")
- }
+ };
},
U: {
g:1,
Wyr = new Date(AWN * ms7d).getUTCFullYear();
return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
- }
+ };
}(),
<div id="method-Date-isLeapYear"></div>/**
var m = this.getMonth();
return m == 1 && this.isLeapYear() ? 29 : daysInMonth[m];
- }
+ };
}(),
<div id="method-Date-getSuffix"></div>/**
console.log('Date.parseDate("1997-13-16T19:20:30.45+01:00", "c", true)= %o', Date.parseDate("1997-13-16T19:20:30.45+01:00", "c", true)); // strict date parsing with invalid month value
console.groupEnd();
-//*/</pre> \r
-</body>\r
+*/
+</pre>
+</body>
</html>
\ No newline at end of file