4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-Date'>/**
19 </span> * @class Ext.Date
20 * A set of useful static methods to deal with date
21 * Note that if Ext.Date is required and loaded, it will copy all methods / properties to
22 * this object for convenience
24 * The date parsing and formatting syntax contains a subset of
25 * <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
26 * supported will provide results equivalent to their PHP versions.
28 * The following is a list of all currently supported formats:
29 * <pre class="">
30 Format Description Example returned values
31 ------ ----------------------------------------------------------------------- -----------------------
32 d Day of the month, 2 digits with leading zeros 01 to 31
33 D A short textual representation of the day of the week Mon to Sun
34 j Day of the month without leading zeros 1 to 31
35 l A full textual representation of the day of the week Sunday to Saturday
36 N ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
37 S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
38 w Numeric representation of the day of the week 0 (for Sunday) to 6 (for Saturday)
39 z The day of the year (starting from 0) 0 to 364 (365 in leap years)
40 W ISO-8601 week number of year, weeks starting on Monday 01 to 53
41 F A full textual representation of a month, such as January or March January to December
42 m Numeric representation of a month, with leading zeros 01 to 12
43 M A short textual representation of a month Jan to Dec
44 n Numeric representation of a month, without leading zeros 1 to 12
45 t Number of days in the given month 28 to 31
46 L Whether it&#39;s a leap year 1 if it is a leap year, 0 otherwise.
47 o ISO-8601 year number (identical to (Y), but if the ISO week number (W) Examples: 1998 or 2004
48 belongs to the previous or next year, that year is used instead)
49 Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
50 y A two digit representation of a year Examples: 99 or 03
51 a Lowercase Ante meridiem and Post meridiem am or pm
52 A Uppercase Ante meridiem and Post meridiem AM or PM
53 g 12-hour format of an hour without leading zeros 1 to 12
54 G 24-hour format of an hour without leading zeros 0 to 23
55 h 12-hour format of an hour with leading zeros 01 to 12
56 H 24-hour format of an hour with leading zeros 00 to 23
57 i Minutes, with leading zeros 00 to 59
58 s Seconds, with leading zeros 00 to 59
59 u Decimal fraction of a second Examples:
60 (minimum 1 digit, arbitrary number of digits allowed) 001 (i.e. 0.001s) or
63 999876543210 (i.e. 0.999876543210s)
64 O Difference to Greenwich time (GMT) in hours and minutes Example: +1030
65 P Difference to Greenwich time (GMT) with colon between hours and minutes Example: -08:00
66 T Timezone abbreviation of the machine running the code Examples: EST, MDT, PDT ...
67 Z Timezone offset in seconds (negative if west of UTC, positive if east) -43200 to 50400
70 1) If unspecified, the month / day defaults to the current month / day, 1991 or
71 the time defaults to midnight, while the timezone defaults to the 1992-10 or
72 browser's timezone. If a time is specified, it must include both hours 1993-09-20 or
73 and minutes. The "T" delimiter, seconds, milliseconds and timezone 1994-08-19T16:20+01:00 or
74 are optional. 1995-07-18T17:21:28-02:00 or
75 2) The decimal fraction of a second, if specified, must contain at 1996-06-17T18:22:29.98765+03:00 or
76 least 1 digit (there is no limit to the maximum number 1997-05-16T19:23:30,12345-0400 or
77 of digits allowed), and may be delimited by either a '.' or a ',' 1998-04-15T20:24:31.2468Z or
78 Refer to the examples on the right for the various levels of 1999-03-14T20:24:32Z or
79 date-time granularity which are supported, or see 2000-02-13T21:25:33
80 http://www.w3.org/TR/NOTE-datetime for more info. 2001-01-12 22:26:34
81 U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1193432466 or -2138434463
82 MS Microsoft AJAX serialized dates \/Date(1238606590509)\/ (i.e. UTC milliseconds since epoch) or
83 \/Date(1238606590509+0800)\/
86 * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
87 * <pre><code>
89 // 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
91 var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
92 console.log(Ext.Date.format(dt, 'Y-m-d')); // 2007-01-10
93 console.log(Ext.Date.format(dt, 'F j, Y, g:i a')); // January 10, 2007, 3:05 pm
94 console.log(Ext.Date.format(dt, 'l, \\t\\he jS \\of F Y h:i:s A')); // Wednesday, the 10th of January 2007 03:05:01 PM
95 </code></pre>
97 * Here are some standard date/time patterns that you might find helpful. They
98 * are not part of the source of Ext.Date, but to use them you can simply copy this
99 * block of code into any script that is included after Ext.Date and they will also become
100 * globally available on the Date object. Feel free to add or remove patterns as needed in your code.
101 * <pre><code>
102 Ext.Date.patterns = {
103 ISO8601Long:"Y-m-d H:i:s",
104 ISO8601Short:"Y-m-d",
105 ShortDate: "n/j/Y",
106 LongDate: "l, F d, Y",
107 FullDateTime: "l, F d, Y g:i:s A",
108 MonthDay: "F d",
109 ShortTime: "g:i A",
110 LongTime: "g:i:s A",
111 SortableDateTime: "Y-m-d\\TH:i:s",
112 UniversalSortableDateTime: "Y-m-d H:i:sO",
113 YearMonth: "F, Y"
115 </code></pre>
118 * <pre><code>
120 console.log(Ext.Date.format(dt, Ext.Date.patterns.ShortDate));
121 </code></pre>
122 * <p>Developer-written, custom formats may be used by supplying both a formatting and a parsing function
123 * which perform to specialized requirements. The functions are stored in {@link #parseFunctions} and {@link #formatFunctions}.</p>
128 * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
129 * (see http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/)
130 * They generate precompiled functions from format patterns instead of parsing and
131 * processing each pattern every time a date is formatted. These functions are available
132 * on every Date object.
137 // create private copy of Ext's Ext.util.Format.format() method
138 // - to remove unnecessary dependency
139 // - to resolve namespace conflict with MS-Ajax's implementation
140 function xf(format) {
141 var args = Array.prototype.slice.call(arguments, 1);
142 return format.replace(/\{(\d+)\}/g, function(m, i) {
148 <span id='Ext-Date-method-now'> /**
149 </span> * Returns the current timestamp
150 * @return {Date} The current timestamp
153 now: Date.now || function() {
157 <span id='Ext-Date-method-toString'> /**
161 toString: function(date) {
162 var pad = Ext.String.leftPad;
164 return date.getFullYear() + "-"
165 + pad(date.getMonth() + 1, 2, '0') + "-"
166 + pad(date.getDate(), 2, '0') + "T"
167 + pad(date.getHours(), 2, '0') + ":"
168 + pad(date.getMinutes(), 2, '0') + ":"
169 + pad(date.getSeconds(), 2, '0');
172 <span id='Ext-Date-method-getElapsed'> /**
173 </span> * Returns the number of milliseconds between two dates
174 * @param {Date} dateA The first date
175 * @param {Date} dateB (optional) The second date, defaults to now
176 * @return {Number} The difference in milliseconds
178 getElapsed: function(dateA, dateB) {
179 return Math.abs(dateA - (dateB || new Date()));
182 <span id='Ext-Date-property-useStrict'> /**
183 </span> * Global flag which determines if strict date parsing should be used.
184 * Strict date parsing will not roll-over invalid dates, which is the
185 * default behaviour of javascript Date objects.
186 * (see {@link #parse} for more information)
187 * Defaults to <tt>false</tt>.
193 formatCodeToRegex: function(character, currentGroup) {
194 // Note: currentGroup - position in regex result array (see notes for Ext.Date.parseCodes below)
195 var p = utilDate.parseCodes[character];
198 p = typeof p == 'function'? p() : p;
199 utilDate.parseCodes[character] = p; // reassign function result to prevent repeated execution
202 return p ? Ext.applyIf({
203 c: p.c ? xf(p.c, currentGroup || "{0}") : p.c
207 s: Ext.String.escapeRegex(character) // treat unrecognised characters as literals
211 <span id='Ext-Date-property-parseFunctions'> /**
212 </span> * <p>An object hash in which each property is a date parsing function. The property name is the
213 * format string which that function parses.</p>
214 * <p>This object is automatically populated with date parsing functions as
215 * date formats are requested for Ext standard formatting strings.</p>
216 * <p>Custom parsing functions may be inserted into this object, keyed by a name which from then on
217 * may be used as a format string to {@link #parse}.<p>
218 * <p>Example:</p><pre><code>
219 Ext.Date.parseFunctions['x-date-format'] = myDateParser;
220 </code></pre>
221 * <p>A parsing function should return a Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
222 * <li><code>date</code> : String<div class="sub-desc">The date string to parse.</div></li>
223 * <li><code>strict</code> : Boolean<div class="sub-desc">True to validate date strings while parsing
224 * (i.e. prevent javascript Date "rollover") (The default must be false).
225 * Invalid date strings should return null when parsed.</div></li>
226 * </ul></div></p>
227 * <p>To enable Dates to also be <i>formatted</i> according to that format, a corresponding
228 * formatting function must be placed into the {@link #formatFunctions} property.
229 * @property parseFunctions
233 "MS": function(input, strict) {
234 // note: the timezone offset is ignored since the MS Ajax server sends
235 // a UTC milliseconds-since-Unix-epoch value (negative values are allowed)
236 var re = new RegExp('\\/Date\\(([-+])?(\\d+)(?:[+-]\\d{4})?\\)\\/');
237 var r = (input || '').match(re);
238 return r? new Date(((r[1] || '') + r[2]) * 1) : null;
243 <span id='Ext-Date-property-formatFunctions'> /**
244 </span> * <p>An object hash in which each property is a date formatting function. The property name is the
245 * format string which corresponds to the produced formatted date string.</p>
246 * <p>This object is automatically populated with date formatting functions as
247 * date formats are requested for Ext standard formatting strings.</p>
248 * <p>Custom formatting functions may be inserted into this object, keyed by a name which from then on
249 * may be used as a format string to {@link #format}. Example:</p><pre><code>
250 Ext.Date.formatFunctions['x-date-format'] = myDateFormatter;
251 </code></pre>
252 * <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>
253 * <li><code>date</code> : Date<div class="sub-desc">The Date to format.</div></li>
254 * </ul></div></p>
255 * <p>To enable date strings to also be <i>parsed</i> according to that format, a corresponding
256 * parsing function must be placed into the {@link #parseFunctions} property.
257 * @property formatFunctions
261 "MS": function() {
262 // UTC milliseconds since Unix epoch (MS-AJAX serialized date format (MRSF))
263 return '\\/Date(' + this.getTime() + ')\\/';
269 <span id='Ext-Date-property-MILLI'> /**
270 </span> * Date interval constant
273 MILLI : "ms",
275 <span id='Ext-Date-property-SECOND'> /**
276 </span> * Date interval constant
279 SECOND : "s",
281 <span id='Ext-Date-property-MINUTE'> /**
282 </span> * Date interval constant
285 MINUTE : "mi",
287 <span id='Ext-Date-property-HOUR'> /** Date interval constant
288 </span> * @type String
290 HOUR : "h",
292 <span id='Ext-Date-property-DAY'> /**
293 </span> * Date interval constant
298 <span id='Ext-Date-property-MONTH'> /**
299 </span> * Date interval constant
302 MONTH : "mo",
304 <span id='Ext-Date-property-YEAR'> /**
305 </span> * Date interval constant
308 YEAR : "y",
310 <span id='Ext-Date-property-defaults'> /**
311 </span> * <p>An object hash containing default date values used during date parsing.</p>
312 * <p>The following properties are available:<div class="mdetail-params"><ul>
313 * <li><code>y</code> : Number<div class="sub-desc">The default year value. (defaults to undefined)</div></li>
314 * <li><code>m</code> : Number<div class="sub-desc">The default 1-based month value. (defaults to undefined)</div></li>
315 * <li><code>d</code> : Number<div class="sub-desc">The default day value. (defaults to undefined)</div></li>
316 * <li><code>h</code> : Number<div class="sub-desc">The default hour value. (defaults to undefined)</div></li>
317 * <li><code>i</code> : Number<div class="sub-desc">The default minute value. (defaults to undefined)</div></li>
318 * <li><code>s</code> : Number<div class="sub-desc">The default second value. (defaults to undefined)</div></li>
319 * <li><code>ms</code> : Number<div class="sub-desc">The default millisecond value. (defaults to undefined)</div></li>
320 * </ul></div></p>
321 * <p>Override these properties to customize the default date values used by the {@link #parse} method.</p>
322 * <p><b>Note: In countries which experience Daylight Saving Time (i.e. DST), the <tt>h</tt>, <tt>i</tt>, <tt>s</tt>
323 * and <tt>ms</tt> properties may coincide with the exact time in which DST takes effect.
324 * It is the responsiblity of the developer to account for this.</b></p>
326 * <pre><code>
327 // set default day value to the first day of the month
328 Ext.Date.defaults.d = 1;
330 // parse a February date string containing only year and month values.
331 // setting the default day value to 1 prevents weird date rollover issues
332 // when attempting to parse the following date string on, for example, March 31st 2009.
333 Ext.Date.parse('2009-02', 'Y-m'); // returns a Date object representing February 1st 2009
334 </code></pre>
340 <span id='Ext-Date-property-dayNames'> /**
341 </span> * @property {String[]} dayNames
342 * An array of textual day names.
343 * Override these values for international dates.
345 * <pre><code>
346 Ext.Date.dayNames = [
351 </code></pre>
357 "Wednesday",
358 "Thursday",
363 <span id='Ext-Date-property-monthNames'> /**
364 </span> * @property {String[]} monthNames
365 * An array of textual month names.
366 * Override these values for international dates.
368 * <pre><code>
369 Ext.Date.monthNames = [
374 </code></pre>
378 "February",
385 "September",
387 "November",
391 <span id='Ext-Date-property-monthNumbers'> /**
392 </span> * @property {Object} monthNumbers
393 * An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are case-sensitive).
394 * Override these values for international dates.
396 * <pre><code>
397 Ext.Date.monthNumbers = {
398 'ShortJanNameInYourLang':0,
399 'ShortFebNameInYourLang':1,
402 </code></pre>
418 <span id='Ext-Date-property-defaultFormat'> /**
419 </span> * @property {String} defaultFormat
420 * <p>The date format string that the {@link Ext.util.Format#dateRenderer}
421 * and {@link Ext.util.Format#date} functions use. See {@link Ext.Date} for details.</p>
422 * <p>This may be overridden in a locale file.</p>
424 defaultFormat : "m/d/Y",
425 <span id='Ext-Date-method-getShortMonthName'> /**
426 </span> * Get the short month name for the given month number.
427 * Override this function for international dates.
428 * @param {Number} month A zero-based javascript month number.
429 * @return {String} The short month name.
431 getShortMonthName : function(month) {
432 return utilDate.monthNames[month].substring(0, 3);
435 <span id='Ext-Date-method-getShortDayName'> /**
436 </span> * Get the short day name for the given day number.
437 * Override this function for international dates.
438 * @param {Number} day A zero-based javascript day number.
439 * @return {String} The short day name.
441 getShortDayName : function(day) {
442 return utilDate.dayNames[day].substring(0, 3);
445 <span id='Ext-Date-method-getMonthNumber'> /**
446 </span> * Get the zero-based javascript month number for the given short/full month name.
447 * Override this function for international dates.
448 * @param {String} name The short/full month name.
449 * @return {Number} The zero-based javascript month number.
451 getMonthNumber : function(name) {
452 // handle camel casing for english month names (since the keys for the Ext.Date.monthNumbers hash are case sensitive)
453 return utilDate.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()];
456 <span id='Ext-Date-method-formatContainsHourInfo'> /**
457 </span> * Checks if the specified format contains hour information
458 * @param {String} format The format to check
459 * @return {Boolean} True if the format contains hour information
462 formatContainsHourInfo : (function(){
463 var stripEscapeRe = /(\\.)/g,
464 hourInfoRe = /([gGhHisucUOPZ]|MS)/;
465 return function(format){
466 return hourInfoRe.test(format.replace(stripEscapeRe, ''));
470 <span id='Ext-Date-method-formatContainsDateInfo'> /**
471 </span> * Checks if the specified format contains information about
472 * anything other than the time.
473 * @param {String} format The format to check
474 * @return {Boolean} True if the format contains information about
475 * date/day information.
478 formatContainsDateInfo : (function(){
479 var stripEscapeRe = /(\\.)/g,
480 dateInfoRe = /([djzmnYycU]|MS)/;
482 return function(format){
483 return dateInfoRe.test(format.replace(stripEscapeRe, ''));
487 <span id='Ext-Date-property-formatCodes'> /**
488 </span> * The base format-code to formatting-function hashmap used by the {@link #format} method.
489 * Formatting functions are strings (or functions which return strings) which
490 * will return the appropriate value when evaluated in the context of the Date object
491 * from which the {@link #format} method is called.
492 * Add to / override these mappings for custom date formatting.
493 * Note: Ext.Date.format() treats characters as literals if an appropriate mapping cannot be found.
495 * <pre><code>
496 Ext.Date.formatCodes.x = "Ext.util.Format.leftPad(this.getDate(), 2, '0')";
497 console.log(Ext.Date.format(new Date(), 'X'); // returns the current day of the month
498 </code></pre>
502 d: "Ext.String.leftPad(this.getDate(), 2, '0')",
503 D: "Ext.Date.getShortDayName(this.getDay())", // get localised short day name
504 j: "this.getDate()",
505 l: "Ext.Date.dayNames[this.getDay()]",
506 N: "(this.getDay() ? this.getDay() : 7)",
507 S: "Ext.Date.getSuffix(this)",
508 w: "this.getDay()",
509 z: "Ext.Date.getDayOfYear(this)",
510 W: "Ext.String.leftPad(Ext.Date.getWeekOfYear(this), 2, '0')",
511 F: "Ext.Date.monthNames[this.getMonth()]",
512 m: "Ext.String.leftPad(this.getMonth() + 1, 2, '0')",
513 M: "Ext.Date.getShortMonthName(this.getMonth())", // get localised short month name
514 n: "(this.getMonth() + 1)",
515 t: "Ext.Date.getDaysInMonth(this)",
516 L: "(Ext.Date.isLeapYear(this) ? 1 : 0)",
517 o: "(this.getFullYear() + (Ext.Date.getWeekOfYear(this) == 1 && this.getMonth() > 0 ? +1 : (Ext.Date.getWeekOfYear(this) >= 52 && this.getMonth() < 11 ? -1 : 0)))",
518 Y: "Ext.String.leftPad(this.getFullYear(), 4, '0')",
519 y: "('' + this.getFullYear()).substring(2, 4)",
520 a: "(this.getHours() < 12 ? 'am' : 'pm')",
521 A: "(this.getHours() < 12 ? 'AM' : 'PM')",
522 g: "((this.getHours() % 12) ? this.getHours() % 12 : 12)",
523 G: "this.getHours()",
524 h: "Ext.String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')",
525 H: "Ext.String.leftPad(this.getHours(), 2, '0')",
526 i: "Ext.String.leftPad(this.getMinutes(), 2, '0')",
527 s: "Ext.String.leftPad(this.getSeconds(), 2, '0')",
528 u: "Ext.String.leftPad(this.getMilliseconds(), 3, '0')",
529 O: "Ext.Date.getGMTOffset(this)",
530 P: "Ext.Date.getGMTOffset(this, true)",
531 T: "Ext.Date.getTimezone(this)",
532 Z: "(this.getTimezoneOffset() * -60)",
534 c: function() { // ISO-8601 -- GMT format
535 for (var c = "Y-m-dTH:i:sP", code = [], i = 0, l = c.length; i < l; ++i) {
537 code.push(e == "T" ? "'T'" : utilDate.getFormatCode(e)); // treat T as a character literal
539 return code.join(" + ");
542 c: function() { // ISO-8601 -- UTC format
544 "this.getUTCFullYear()", "'-'",
545 "Ext.util.Format.leftPad(this.getUTCMonth() + 1, 2, '0')", "'-'",
546 "Ext.util.Format.leftPad(this.getUTCDate(), 2, '0')",
548 "Ext.util.Format.leftPad(this.getUTCHours(), 2, '0')", "':'",
549 "Ext.util.Format.leftPad(this.getUTCMinutes(), 2, '0')", "':'",
550 "Ext.util.Format.leftPad(this.getUTCSeconds(), 2, '0')",
552 ].join(" + ");
556 U: "Math.round(this.getTime() / 1000)"
559 <span id='Ext-Date-method-isValid'> /**
560 </span> * Checks if the passed Date parameters will cause a javascript Date "rollover".
561 * @param {Number} year 4-digit year
562 * @param {Number} month 1-based month-of-year
563 * @param {Number} day Day of month
564 * @param {Number} hour (optional) Hour
565 * @param {Number} minute (optional) Minute
566 * @param {Number} second (optional) Second
567 * @param {Number} millisecond (optional) Millisecond
568 * @return {Boolean} true if the passed parameters do not cause a Date "rollover", false otherwise.
570 isValid : function(y, m, d, h, i, s, ms) {
577 // Special handling for year < 100
578 var dt = utilDate.add(new Date(y < 100 ? 100 : y, m - 1, d, h, i, s, ms), utilDate.YEAR, y < 100 ? y - 100 : 0);
580 return y == dt.getFullYear() &&
581 m == dt.getMonth() + 1 &&
582 d == dt.getDate() &&
583 h == dt.getHours() &&
584 i == dt.getMinutes() &&
585 s == dt.getSeconds() &&
586 ms == dt.getMilliseconds();
589 <span id='Ext-Date-method-parse'> /**
590 </span> * Parses the passed string using the specified date format.
591 * Note that this function expects normal calendar dates, meaning that months are 1-based (i.e. 1 = January).
592 * The {@link #defaults} hash will be used for any date value (i.e. year, month, day, hour, minute, second or millisecond)
593 * which cannot be found in the passed string. If a corresponding default date value has not been specified in the {@link #defaults} hash,
594 * the current date's year, month, day or DST-adjusted zero-hour time value will be used instead.
595 * Keep in mind that the input date string must precisely match the specified format string
596 * in order for the parse operation to be successful (failed parse operations return a null value).
597 * <p>Example:</p><pre><code>
598 //dt = Fri May 25 2007 (current date)
601 //dt = Thu May 25 2006 (today&#39;s month/day in 2006)
602 dt = Ext.Date.parse("2006", "Y");
604 //dt = Sun Jan 15 2006 (all date parts specified)
605 dt = Ext.Date.parse("2006-01-15", "Y-m-d");
607 //dt = Sun Jan 15 2006 15:20:01
608 dt = Ext.Date.parse("2006-01-15 3:20:01 PM", "Y-m-d g:i:s A");
610 // attempt to parse Sun Feb 29 2006 03:20:01 in strict mode
611 dt = Ext.Date.parse("2006-02-29 03:20:01", "Y-m-d H:i:s", true); // returns null
612 </code></pre>
613 * @param {String} input The raw date string.
614 * @param {String} format The expected date string format.
615 * @param {Boolean} strict (optional) True to validate date strings while parsing (i.e. prevents javascript Date "rollover")
616 (defaults to false). Invalid date strings will return null when parsed.
617 * @return {Date} The parsed Date.
619 parse : function(input, format, strict) {
620 var p = utilDate.parseFunctions;
621 if (p[format] == null) {
622 utilDate.createParser(format);
624 return p[format](input, Ext.isDefined(strict) ? strict : utilDate.useStrict);
628 parseDate: function(input, format, strict){
629 return utilDate.parse(input, format, strict);
634 getFormatCode : function(character) {
635 var f = utilDate.formatCodes[character];
638 f = typeof f == 'function'? f() : f;
639 utilDate.formatCodes[character] = f; // reassign function result to prevent repeated execution
642 // note: unknown characters are treated as literals
643 return f || ("'" + Ext.String.escape(character) + "'");
647 createFormat : function(format) {
652 for (var i = 0; i < format.length; ++i) {
653 ch = format.charAt(i);
654 if (!special && ch == "\\") {
656 } else if (special) {
658 code.push("'" + Ext.String.escape(ch) + "'");
660 code.push(utilDate.getFormatCode(ch));
663 utilDate.formatFunctions[format] = Ext.functionFactory("return " + code.join('+'));
667 createParser : (function() {
669 "var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,",
670 "def = Ext.Date.defaults,",
671 "results = String(input).match(Ext.Date.parseRegexes[{0}]);", // either null, or an array of matched strings
673 "if(results){",
676 "if(u != null){", // i.e. unix time is defined
677 "v = new Date(u * 1000);", // give top priority to UNIX time
679 // create Date object representing midnight of the current day;
680 // this will provide us with our date defaults
681 // (note: clearTime() handles Daylight Saving Time automatically)
682 "dt = Ext.Date.clearTime(new Date);",
684 // date calculations (note: these calculations create a dependency on Ext.Number.from())
685 "y = Ext.Number.from(y, Ext.Number.from(def.y, dt.getFullYear()));",
686 "m = Ext.Number.from(m, Ext.Number.from(def.m - 1, dt.getMonth()));",
687 "d = Ext.Number.from(d, Ext.Number.from(def.d, dt.getDate()));",
689 // time calculations (note: these calculations create a dependency on Ext.Number.from())
690 "h = Ext.Number.from(h, Ext.Number.from(def.h, dt.getHours()));",
691 "i = Ext.Number.from(i, Ext.Number.from(def.i, dt.getMinutes()));",
692 "s = Ext.Number.from(s, Ext.Number.from(def.s, dt.getSeconds()));",
693 "ms = Ext.Number.from(ms, Ext.Number.from(def.ms, dt.getMilliseconds()));",
695 "if(z >= 0 && y >= 0){",
696 // both the year and zero-based day of year are defined and >= 0.
697 // these 2 values alone provide sufficient info to create a full date object
699 // create Date object representing January 1st for the given year
700 // handle years < 100 appropriately
701 "v = Ext.Date.add(new Date(y < 100 ? 100 : y, 0, 1, h, i, s, ms), Ext.Date.YEAR, y < 100 ? y - 100 : 0);",
703 // then add day of year, checking for Date "rollover" if necessary
704 "v = !strict? v : (strict === true && (z <= 364 || (Ext.Date.isLeapYear(v) && z <= 365))? Ext.Date.add(v, Ext.Date.DAY, z) : null);",
705 "}else if(strict === true && !Ext.Date.isValid(y, m + 1, d, h, i, s, ms)){", // check for Date "rollover"
706 "v = null;", // invalid date, so return null
708 // plain old Date object
709 // handle years < 100 properly
710 "v = Ext.Date.add(new Date(y < 100 ? 100 : y, m, d, h, i, s, ms), Ext.Date.YEAR, y < 100 ? y - 100 : 0);",
716 // favour UTC offset over GMT offset
717 "if(zz != null){",
718 // reset to UTC, then add offset
719 "v = Ext.Date.add(v, Ext.Date.SECOND, -v.getTimezoneOffset() * 60 - zz);",
720 "}else if(o){",
721 // reset to GMT, then add offset
722 "v = Ext.Date.add(v, Ext.Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn));",
726 "return v;"
729 return function(format) {
730 var regexNum = utilDate.parseRegexes.length,
737 for (var i = 0; i < format.length; ++i) {
738 ch = format.charAt(i);
739 if (!special && ch == "\\") {
741 } else if (special) {
743 regex.push(Ext.String.escape(ch));
745 var obj = utilDate.formatCodeToRegex(ch, currentGroup);
746 currentGroup += obj.g;
748 if (obj.g && obj.c) {
754 utilDate.parseRegexes[regexNum] = new RegExp("^" + regex.join('') + "$", 'i');
755 utilDate.parseFunctions[format] = Ext.functionFactory("input", "strict", xf(code, regexNum, calc.join('')));
763 * g = {Number} calculation group (0 or 1. only group 1 contributes to date calculations.)
764 * c = {String} calculation method (required for group 1. null for group 0. {0} = currentGroup - position in regex result array)
765 * s = {String} regex pattern. all matches are stored in results[], and are accessible by the calculation mapped to 'c'
769 c:"d = parseInt(results[{0}], 10);\n",
770 s:"(\\d{2})" // day of month with leading zeroes (01 - 31)
774 c:"d = parseInt(results[{0}], 10);\n",
775 s:"(\\d{1,2})" // day of month without leading zeroes (1 - 31)
778 for (var a = [], i = 0; i < 7; a.push(utilDate.getShortDayName(i)), ++i); // get localised short day names
782 s:"(?:" + a.join("|") +")"
789 s:"(?:" + utilDate.dayNames.join("|") + ")"
795 s:"[1-7]" // ISO-8601 day number (1 (monday) - 7 (sunday))
800 s:"(?:st|nd|rd|th)"
805 s:"[0-6]" // javascript day number (0 (sunday) - 6 (saturday))
809 c:"z = parseInt(results[{0}], 10);\n",
810 s:"(\\d{1,3})" // day of the year (0 - 364 (365 in leap years))
815 s:"(?:\\d{2})" // ISO-8601 week number (with leading zero)
820 c:"m = parseInt(Ext.Date.getMonthNumber(results[{0}]), 10);\n", // get localised month number
821 s:"(" + utilDate.monthNames.join("|") + ")"
825 for (var a = [], i = 0; i < 12; a.push(utilDate.getShortMonthName(i)), ++i); // get localised short month names
827 s:"(" + a.join("|") + ")"
828 }, utilDate.formatCodeToRegex("F"));
832 c:"m = parseInt(results[{0}], 10) - 1;\n",
833 s:"(\\d{2})" // month number with leading zeros (01 - 12)
837 c:"m = parseInt(results[{0}], 10) - 1;\n",
838 s:"(\\d{1,2})" // month number without leading zeros (1 - 12)
843 s:"(?:\\d{2})" // no. of days in the month (28 - 31)
848 s:"(?:1|0)"
851 return utilDate.formatCodeToRegex("Y");
855 c:"y = parseInt(results[{0}], 10);\n",
856 s:"(\\d{4})" // 4-digit year
860 c:"var ty = parseInt(results[{0}], 10);\n"
861 + "y = ty > Ext.Date.y2kYear ? 1900 + ty : 2000 + ty;\n", // 2-digit year
862 s:"(\\d{1,2})"
865 * In the am/pm parsing routines, we allow both upper and lower case
866 * even though it doesn't exactly match the spec. It gives much more flexibility
867 * in being able to specify case insensitive regexes.
871 c:"if (/(am)/i.test(results[{0}])) {\n"
872 + "if (!h || h == 12) { h = 0; }\n"
873 + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
874 s:"(am|pm|AM|PM)"
878 c:"if (/(am)/i.test(results[{0}])) {\n"
879 + "if (!h || h == 12) { h = 0; }\n"
880 + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
881 s:"(AM|PM|am|pm)"
884 return utilDate.formatCodeToRegex("G");
888 c:"h = parseInt(results[{0}], 10);\n",
889 s:"(\\d{1,2})" // 24-hr format of an hour without leading zeroes (0 - 23)
892 return utilDate.formatCodeToRegex("H");
896 c:"h = parseInt(results[{0}], 10);\n",
897 s:"(\\d{2})" // 24-hr format of an hour with leading zeroes (00 - 23)
901 c:"i = parseInt(results[{0}], 10);\n",
902 s:"(\\d{2})" // minutes with leading zeros (00 - 59)
906 c:"s = parseInt(results[{0}], 10);\n",
907 s:"(\\d{2})" // seconds with leading zeros (00 - 59)
911 c:"ms = results[{0}]; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n",
912 s:"(\\d+)" // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
917 "o = results[{0}];",
918 "var sn = o.substring(0,1),", // get + / - sign
919 "hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
920 "mn = o.substring(3,5) % 60;", // get minutes
921 "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + Ext.String.leftPad(hr, 2, '0') + Ext.String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
922 ].join("\n"),
923 s: "([+\-]\\d{4})" // GMT offset in hrs and mins
928 "o = results[{0}];",
929 "var sn = o.substring(0,1),", // get + / - sign
930 "hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
931 "mn = o.substring(4,6) % 60;", // get minutes
932 "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + Ext.String.leftPad(hr, 2, '0') + Ext.String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
933 ].join("\n"),
934 s: "([+\-]\\d{2}:\\d{2})" // GMT offset in hrs and mins (with colon separator)
939 s:"[A-Z]{1,4}" // timezone abbrev. may be between 1 - 4 chars
943 c:"zz = results[{0}] * 1;\n" // -43200 <= UTC offset <= 50400
944 + "zz = (-43200 <= zz && zz <= 50400)? zz : null;\n",
945 s:"([+\-]?\\d{1,5})" // leading '+' sign is optional for UTC offset
950 utilDate.formatCodeToRegex("Y", 1), // year
951 utilDate.formatCodeToRegex("m", 2), // month
952 utilDate.formatCodeToRegex("d", 3), // day
953 utilDate.formatCodeToRegex("h", 4), // hour
954 utilDate.formatCodeToRegex("i", 5), // minute
955 utilDate.formatCodeToRegex("s", 6), // second
956 {c:"ms = results[7] || '0'; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n"}, // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
957 {c:[ // allow either "Z" (i.e. UTC) or "-0530" or "+08:00" (i.e. UTC offset) timezone delimiters. assumes local timezone if no timezone is specified
958 "if(results[8]) {", // timezone specified
959 "if(results[8] == 'Z'){",
960 "zz = 0;", // UTC
961 "}else if (results[8].indexOf(':') > -1){",
962 utilDate.formatCodeToRegex("P", 8).c, // timezone offset with colon separator
964 utilDate.formatCodeToRegex("O", 8).c, // timezone offset without colon separator
970 for (var i = 0, l = arr.length; i < l; ++i) {
976 c:calc.join(""),
978 arr[0].s, // year (required)
979 "(?:", "-", arr[1].s, // month (optional)
980 "(?:", "-", arr[2].s, // day (optional)
982 "(?:T| )?", // time delimiter -- either a "T" or a single blank space
983 arr[3].s, ":", arr[4].s, // hour AND minute, delimited by a single colon (optional). MUST be preceded by either a "T" or a single blank space
984 "(?::", arr[5].s, ")?", // seconds (optional)
985 "(?:(?:\\.|,)(\\d+))?", // decimal fraction of a second (e.g. ",12345" or ".98765") (optional)
986 "(Z|(?:[-+]\\d{2}(?::)?\\d{2}))?", // "Z" (UTC) or "-0530" (UTC offset without colon delimiter) or "+08:00" (UTC offset with colon delimiter) (optional)
995 c:"u = parseInt(results[{0}], 10);\n",
996 s:"(-?\\d+)" // leading minus sign indicates seconds before UNIX epoch
1000 //Old Ext.Date prototype methods.
1002 dateFormat: function(date, format) {
1003 return utilDate.format(date, format);
1006 <span id='Ext-Date-method-format'> /**
1007 </span> * Formats a date given the supplied format string.
1008 * @param {Date} date The date to format
1009 * @param {String} format The format string
1010 * @return {String} The formatted date
1012 format: function(date, format) {
1013 if (utilDate.formatFunctions[format] == null) {
1014 utilDate.createFormat(format);
1016 var result = utilDate.formatFunctions[format].call(date);
1020 <span id='Ext-Date-method-getTimezone'> /**
1021 </span> * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
1023 * Note: The date string returned by the javascript Date object's toString() method varies
1024 * between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America).
1025 * For a given date string e.g. "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)",
1026 * getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses
1027 * (which may or may not be present), failing which it proceeds to get the timezone abbreviation
1028 * from the GMT offset portion of the date string.
1029 * @param {Date} date The date
1030 * @return {String} The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).
1032 getTimezone : function(date) {
1033 // the following list shows the differences between date strings from different browsers on a WinXP SP2 machine from an Asian locale:
1035 // Opera : "Thu, 25 Oct 2007 22:53:45 GMT+0800" -- shortest (weirdest) date string of the lot
1036 // Safari : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone (same as FF)
1037 // FF : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone
1038 // IE : "Thu Oct 25 22:54:35 UTC+0800 2007" -- (Asian system setting) look for 3-4 letter timezone abbrev
1039 // IE : "Thu Oct 25 17:06:37 PDT 2007" -- (American system setting) look for 3-4 letter timezone abbrev
1041 // this crazy regex attempts to guess the correct timezone abbreviation despite these differences.
1042 // step 1: (?:\((.*)\) -- find timezone in parentheses
1043 // step 2: ([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?) -- if nothing was found in step 1, find timezone from timezone offset portion of date string
1044 // step 3: remove all non uppercase characters found in step 1 and 2
1045 return date.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, "");
1048 <span id='Ext-Date-method-getGMTOffset'> /**
1049 </span> * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
1050 * @param {Date} date The date
1051 * @param {Boolean} colon (optional) true to separate the hours and minutes with a colon (defaults to false).
1052 * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600').
1054 getGMTOffset : function(date, colon) {
1055 var offset = date.getTimezoneOffset();
1056 return (offset > 0 ? "-" : "+")
1057 + Ext.String.leftPad(Math.floor(Math.abs(offset) / 60), 2, "0")
1058 + (colon ? ":" : "")
1059 + Ext.String.leftPad(Math.abs(offset % 60), 2, "0");
1062 <span id='Ext-Date-method-getDayOfYear'> /**
1063 </span> * Get the numeric day number of the year, adjusted for leap year.
1064 * @param {Date} date The date
1065 * @return {Number} 0 to 364 (365 in leap years).
1067 getDayOfYear: function(date) {
1069 d = Ext.Date.clone(date),
1070 m = date.getMonth(),
1073 for (i = 0, d.setDate(1), d.setMonth(0); i < m; d.setMonth(++i)) {
1074 num += utilDate.getDaysInMonth(d);
1076 return num + date.getDate() - 1;
1079 <span id='Ext-Date-method-getWeekOfYear'> /**
1080 </span> * Get the numeric ISO-8601 week number of the year.
1081 * (equivalent to the format specifier 'W', but without a leading zero).
1082 * @param {Date} date The date
1083 * @return {Number} 1 to 53
1086 getWeekOfYear : (function() {
1087 // adapted from http://www.merlyn.demon.co.uk/weekcalc.htm
1088 var ms1d = 864e5, // milliseconds in a day
1089 ms7d = 7 * ms1d; // milliseconds in a week
1091 return function(date) { // return a closure so constants get calculated only once
1092 var DC3 = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate() + 3) / ms1d, // an Absolute Day Number
1093 AWN = Math.floor(DC3 / 7), // an Absolute Week Number
1094 Wyr = new Date(AWN * ms7d).getUTCFullYear();
1096 return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
1100 <span id='Ext-Date-method-isLeapYear'> /**
1101 </span> * Checks if the current date falls within a leap year.
1102 * @param {Date} date The date
1103 * @return {Boolean} True if the current date falls within a leap year, false otherwise.
1105 isLeapYear : function(date) {
1106 var year = date.getFullYear();
1107 return !!((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
1110 <span id='Ext-Date-method-getFirstDayOfMonth'> /**
1111 </span> * Get the first day of the current month, adjusted for leap year. The returned value
1112 * is the numeric day index within the week (0-6) which can be used in conjunction with
1113 * the {@link #monthNames} array to retrieve the textual day name.
1115 * <pre><code>
1116 var dt = new Date('1/10/2007'),
1117 firstDay = Ext.Date.getFirstDayOfMonth(dt);
1118 console.log(Ext.Date.dayNames[firstDay]); //output: 'Monday'
1119 * </code></pre>
1120 * @param {Date} date The date
1121 * @return {Number} The day number (0-6).
1123 getFirstDayOfMonth : function(date) {
1124 var day = (date.getDay() - (date.getDate() - 1)) % 7;
1125 return (day < 0) ? (day + 7) : day;
1128 <span id='Ext-Date-method-getLastDayOfMonth'> /**
1129 </span> * Get the last day of the current month, adjusted for leap year. The returned value
1130 * is the numeric day index within the week (0-6) which can be used in conjunction with
1131 * the {@link #monthNames} array to retrieve the textual day name.
1133 * <pre><code>
1134 var dt = new Date('1/10/2007'),
1135 lastDay = Ext.Date.getLastDayOfMonth(dt);
1136 console.log(Ext.Date.dayNames[lastDay]); //output: 'Wednesday'
1137 * </code></pre>
1138 * @param {Date} date The date
1139 * @return {Number} The day number (0-6).
1141 getLastDayOfMonth : function(date) {
1142 return utilDate.getLastDateOfMonth(date).getDay();
1146 <span id='Ext-Date-method-getFirstDateOfMonth'> /**
1147 </span> * Get the date of the first day of the month in which this date resides.
1148 * @param {Date} date The date
1151 getFirstDateOfMonth : function(date) {
1152 return new Date(date.getFullYear(), date.getMonth(), 1);
1155 <span id='Ext-Date-method-getLastDateOfMonth'> /**
1156 </span> * Get the date of the last day of the month in which this date resides.
1157 * @param {Date} date The date
1160 getLastDateOfMonth : function(date) {
1161 return new Date(date.getFullYear(), date.getMonth(), utilDate.getDaysInMonth(date));
1164 <span id='Ext-Date-method-getDaysInMonth'> /**
1165 </span> * Get the number of days in the current month, adjusted for leap year.
1166 * @param {Date} date The date
1167 * @return {Number} The number of days in the month.
1170 getDaysInMonth: (function() {
1171 var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
1173 return function(date) { // return a closure for efficiency
1174 var m = date.getMonth();
1176 return m == 1 && utilDate.isLeapYear(date) ? 29 : daysInMonth[m];
1180 <span id='Ext-Date-method-getSuffix'> /**
1181 </span> * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
1182 * @param {Date} date The date
1183 * @return {String} 'st, 'nd', 'rd' or 'th'.
1185 getSuffix : function(date) {
1186 switch (date.getDate()) {
1190 return "st";
1193 return "nd";
1196 return "rd";
1198 return "th";
1202 <span id='Ext-Date-method-clone'> /**
1203 </span> * Creates and returns a new Date instance with the exact same date value as the called instance.
1204 * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
1205 * variable will also be changed. When the intention is to create a new variable that will not
1206 * modify the original instance, you should create a clone.
1208 * Example of correctly cloning a date:
1209 * <pre><code>
1211 var orig = new Date('10/1/2006');
1214 console.log(orig); //returns 'Thu Oct 05 2006'!
1217 var orig = new Date('10/1/2006'),
1218 copy = Ext.Date.clone(orig);
1220 console.log(orig); //returns 'Thu Oct 01 2006'
1221 * </code></pre>
1222 * @param {Date} date The date
1223 * @return {Date} The new Date instance.
1225 clone : function(date) {
1226 return new Date(date.getTime());
1229 <span id='Ext-Date-method-isDST'> /**
1230 </span> * Checks if the current date is affected by Daylight Saving Time (DST).
1231 * @param {Date} date The date
1232 * @return {Boolean} True if the current date is affected by DST.
1234 isDST : function(date) {
1235 // adapted from http://sencha.com/forum/showthread.php?p=247172#post247172
1236 // courtesy of @geoffrey.mcgill
1237 return new Date(date.getFullYear(), 0, 1).getTimezoneOffset() != date.getTimezoneOffset();
1240 <span id='Ext-Date-method-clearTime'> /**
1241 </span> * Attempts to clear all time information from this Date by setting the time to midnight of the same day,
1242 * automatically adjusting for Daylight Saving Time (DST) where applicable.
1243 * (note: DST timezone information for the browser's host operating system is assumed to be up-to-date)
1244 * @param {Date} date The date
1245 * @param {Boolean} clone true to create a clone of this date, clear the time and return it (defaults to false).
1246 * @return {Date} this or the clone.
1248 clearTime : function(date, clone) {
1250 return Ext.Date.clearTime(Ext.Date.clone(date));
1253 // get current date before clearing time
1254 var d = date.getDate();
1260 date.setMilliseconds(0);
1262 if (date.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
1263 // note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the case)
1264 // refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
1266 // increment hour until cloned date == current date
1267 for (var hr = 1, c = utilDate.add(date, Ext.Date.HOUR, hr); c.getDate() != d; hr++, c = utilDate.add(date, Ext.Date.HOUR, hr));
1270 date.setHours(c.getHours());
1276 <span id='Ext-Date-method-add'> /**
1277 </span> * Provides a convenient method for performing basic date arithmetic. This method
1278 * does not modify the Date instance being called - it creates and returns
1279 * a new Date instance containing the resulting date value.
1282 * <pre><code>
1284 var dt = Ext.Date.add(new Date('10/29/2006'), Ext.Date.DAY, 5);
1285 console.log(dt); //returns 'Fri Nov 03 2006 00:00:00'
1287 // Negative values will be subtracted:
1288 var dt2 = Ext.Date.add(new Date('10/1/2006'), Ext.Date.DAY, -5);
1289 console.log(dt2); //returns 'Tue Sep 26 2006 00:00:00'
1291 * </code></pre>
1293 * @param {Date} date The date to modify
1294 * @param {String} interval A valid date interval enum value.
1295 * @param {Number} value The amount to add to the current date.
1296 * @return {Date} The new Date instance.
1298 add : function(date, interval, value) {
1299 var d = Ext.Date.clone(date),
1301 if (!interval || value === 0) return d;
1303 switch(interval.toLowerCase()) {
1304 case Ext.Date.MILLI:
1305 d.setMilliseconds(d.getMilliseconds() + value);
1307 case Ext.Date.SECOND:
1308 d.setSeconds(d.getSeconds() + value);
1310 case Ext.Date.MINUTE:
1311 d.setMinutes(d.getMinutes() + value);
1314 d.setHours(d.getHours() + value);
1317 d.setDate(d.getDate() + value);
1319 case Ext.Date.MONTH:
1320 var day = date.getDate();
1322 day = Math.min(day, Ext.Date.getLastDateOfMonth(Ext.Date.add(Ext.Date.getFirstDateOfMonth(date), 'mo', value)).getDate());
1325 d.setMonth(date.getMonth() + value);
1328 d.setFullYear(date.getFullYear() + value);
1334 <span id='Ext-Date-method-between'> /**
1335 </span> * Checks if a date falls on or between the given start and end dates.
1336 * @param {Date} date The date to check
1337 * @param {Date} start Start date
1338 * @param {Date} end End date
1339 * @return {Boolean} true if this date falls on or between the given start and end dates.
1341 between : function(date, start, end) {
1342 var t = date.getTime();
1343 return start.getTime() <= t && t <= end.getTime();
1346 //Maintains compatibility with old static and prototype window.Date methods.
1347 compat: function() {
1348 var nativeDate = window.Date,
1350 statics = ['useStrict', 'formatCodeToRegex', 'parseFunctions', 'parseRegexes', 'formatFunctions', 'y2kYear', 'MILLI', 'SECOND', 'MINUTE', 'HOUR', 'DAY', 'MONTH', 'YEAR', 'defaults', 'dayNames', 'monthNames', 'monthNumbers', 'getShortMonthName', 'getShortDayName', 'getMonthNumber', 'formatCodes', 'isValid', 'parseDate', 'getFormatCode', 'createFormat', 'createParser', 'parseCodes'],
1351 proto = ['dateFormat', 'format', 'getTimezone', 'getGMTOffset', 'getDayOfYear', 'getWeekOfYear', 'isLeapYear', 'getFirstDayOfMonth', 'getLastDayOfMonth', 'getDaysInMonth', 'getSuffix', 'clone', 'isDST', 'clearTime', 'add', 'between'];
1354 Ext.Array.forEach(statics, function(s) {
1355 nativeDate[s] = utilDate[s];
1358 //Append to prototype
1359 Ext.Array.forEach(proto, function(s) {
1360 nativeDate.prototype[s] = function() {
1361 var args = Array.prototype.slice.call(arguments);
1363 return utilDate[s].apply(utilDate, args);
1369 var utilDate = Ext.Date;