4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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>.
194 formatCodeToRegex: function(character, currentGroup) {
195 // Note: currentGroup - position in regex result array (see notes for Ext.Date.parseCodes below)
196 var p = utilDate.parseCodes[character];
199 p = typeof p == 'function'? p() : p;
200 utilDate.parseCodes[character] = p; // reassign function result to prevent repeated execution
203 return p ? Ext.applyIf({
204 c: p.c ? xf(p.c, currentGroup || "{0}") : p.c
208 s: Ext.String.escapeRegex(character) // treat unrecognised characters as literals
212 <span id='Ext-Date-property-parseFunctions'> /**
213 </span> * <p>An object hash in which each property is a date parsing function. The property name is the
214 * format string which that function parses.</p>
215 * <p>This object is automatically populated with date parsing functions as
216 * date formats are requested for Ext standard formatting strings.</p>
217 * <p>Custom parsing functions may be inserted into this object, keyed by a name which from then on
218 * may be used as a format string to {@link #parse}.<p>
219 * <p>Example:</p><pre><code>
220 Ext.Date.parseFunctions['x-date-format'] = myDateParser;
221 </code></pre>
222 * <p>A parsing function should return a Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
223 * <li><code>date</code> : String<div class="sub-desc">The date string to parse.</div></li>
224 * <li><code>strict</code> : Boolean<div class="sub-desc">True to validate date strings while parsing
225 * (i.e. prevent javascript Date "rollover") (The default must be false).
226 * Invalid date strings should return null when parsed.</div></li>
227 * </ul></div></p>
228 * <p>To enable Dates to also be <i>formatted</i> according to that format, a corresponding
229 * formatting function must be placed into the {@link #formatFunctions} property.
230 * @property parseFunctions
235 "MS": function(input, strict) {
236 // note: the timezone offset is ignored since the MS Ajax server sends
237 // a UTC milliseconds-since-Unix-epoch value (negative values are allowed)
238 var re = new RegExp('\\/Date\\(([-+])?(\\d+)(?:[+-]\\d{4})?\\)\\/');
239 var r = (input || '').match(re);
240 return r? new Date(((r[1] || '') + r[2]) * 1) : null;
245 <span id='Ext-Date-property-formatFunctions'> /**
246 </span> * <p>An object hash in which each property is a date formatting function. The property name is the
247 * format string which corresponds to the produced formatted date string.</p>
248 * <p>This object is automatically populated with date formatting functions as
249 * date formats are requested for Ext standard formatting strings.</p>
250 * <p>Custom formatting functions may be inserted into this object, keyed by a name which from then on
251 * may be used as a format string to {@link #format}. Example:</p><pre><code>
252 Ext.Date.formatFunctions['x-date-format'] = myDateFormatter;
253 </code></pre>
254 * <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>
255 * <li><code>date</code> : Date<div class="sub-desc">The Date to format.</div></li>
256 * </ul></div></p>
257 * <p>To enable date strings to also be <i>parsed</i> according to that format, a corresponding
258 * parsing function must be placed into the {@link #parseFunctions} property.
259 * @property formatFunctions
264 "MS": function() {
265 // UTC milliseconds since Unix epoch (MS-AJAX serialized date format (MRSF))
266 return '\\/Date(' + this.getTime() + ')\\/';
272 <span id='Ext-Date-property-MILLI'> /**
273 </span> * Date interval constant
277 MILLI : "ms",
279 <span id='Ext-Date-property-SECOND'> /**
280 </span> * Date interval constant
284 SECOND : "s",
286 <span id='Ext-Date-property-MINUTE'> /**
287 </span> * Date interval constant
291 MINUTE : "mi",
293 <span id='Ext-Date-property-HOUR'> /** Date interval constant
297 HOUR : "h",
299 <span id='Ext-Date-property-DAY'> /**
300 </span> * Date interval constant
306 <span id='Ext-Date-property-MONTH'> /**
307 </span> * Date interval constant
311 MONTH : "mo",
313 <span id='Ext-Date-property-YEAR'> /**
314 </span> * Date interval constant
318 YEAR : "y",
320 <span id='Ext-Date-property-defaults'> /**
321 </span> * <p>An object hash containing default date values used during date parsing.</p>
322 * <p>The following properties are available:<div class="mdetail-params"><ul>
323 * <li><code>y</code> : Number<div class="sub-desc">The default year value. (defaults to undefined)</div></li>
324 * <li><code>m</code> : Number<div class="sub-desc">The default 1-based month value. (defaults to undefined)</div></li>
325 * <li><code>d</code> : Number<div class="sub-desc">The default day value. (defaults to undefined)</div></li>
326 * <li><code>h</code> : Number<div class="sub-desc">The default hour value. (defaults to undefined)</div></li>
327 * <li><code>i</code> : Number<div class="sub-desc">The default minute value. (defaults to undefined)</div></li>
328 * <li><code>s</code> : Number<div class="sub-desc">The default second value. (defaults to undefined)</div></li>
329 * <li><code>ms</code> : Number<div class="sub-desc">The default millisecond value. (defaults to undefined)</div></li>
330 * </ul></div></p>
331 * <p>Override these properties to customize the default date values used by the {@link #parse} method.</p>
332 * <p><b>Note: In countries which experience Daylight Saving Time (i.e. DST), the <tt>h</tt>, <tt>i</tt>, <tt>s</tt>
333 * and <tt>ms</tt> properties may coincide with the exact time in which DST takes effect.
334 * It is the responsiblity of the developer to account for this.</b></p>
336 * <pre><code>
337 // set default day value to the first day of the month
338 Ext.Date.defaults.d = 1;
340 // parse a February date string containing only year and month values.
341 // setting the default day value to 1 prevents weird date rollover issues
342 // when attempting to parse the following date string on, for example, March 31st 2009.
343 Ext.Date.parse('2009-02', 'Y-m'); // returns a Date object representing February 1st 2009
344 </code></pre>
351 <span id='Ext-Date-property-dayNames'> /**
352 </span> * An array of textual day names.
353 * Override these values for international dates.
355 * <pre><code>
356 Ext.Date.dayNames = [
361 </code></pre>
369 "Wednesday",
370 "Thursday",
375 <span id='Ext-Date-property-monthNames'> /**
376 </span> * An array of textual month names.
377 * Override these values for international dates.
379 * <pre><code>
380 Ext.Date.monthNames = [
385 </code></pre>
391 "February",
398 "September",
400 "November",
404 <span id='Ext-Date-property-monthNumbers'> /**
405 </span> * An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are case-sensitive).
406 * Override these values for international dates.
408 * <pre><code>
409 Ext.Date.monthNumbers = {
410 'ShortJanNameInYourLang':0,
411 'ShortFebNameInYourLang':1,
414 </code></pre>
432 <span id='Ext-Date-property-defaultFormat'> /**
433 </span> * <p>The date format string that the {@link #dateRenderer} and {@link #date} functions use.
434 * see {@link #Date} for details.</p>
435 * <p>This defaults to <code>m/d/Y</code>, but may be overridden in a locale file.</p>
436 * @property defaultFormat
440 defaultFormat : "m/d/Y",
441 <span id='Ext-Date-method-getShortMonthName'> /**
442 </span> * Get the short month name for the given month number.
443 * Override this function for international dates.
444 * @param {Number} month A zero-based javascript month number.
445 * @return {String} The short month name.
448 getShortMonthName : function(month) {
449 return utilDate.monthNames[month].substring(0, 3);
452 <span id='Ext-Date-method-getShortDayName'> /**
453 </span> * Get the short day name for the given day number.
454 * Override this function for international dates.
455 * @param {Number} day A zero-based javascript day number.
456 * @return {String} The short day name.
459 getShortDayName : function(day) {
460 return utilDate.dayNames[day].substring(0, 3);
463 <span id='Ext-Date-method-getMonthNumber'> /**
464 </span> * Get the zero-based javascript month number for the given short/full month name.
465 * Override this function for international dates.
466 * @param {String} name The short/full month name.
467 * @return {Number} The zero-based javascript month number.
470 getMonthNumber : function(name) {
471 // handle camel casing for english month names (since the keys for the Ext.Date.monthNumbers hash are case sensitive)
472 return utilDate.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()];
475 <span id='Ext-Date-method-formatContainsHourInfo'> /**
476 </span> * Checks if the specified format contains hour information
477 * @param {String} format The format to check
478 * @return {Boolean} True if the format contains hour information
482 formatContainsHourInfo : (function(){
483 var stripEscapeRe = /(\\.)/g,
484 hourInfoRe = /([gGhHisucUOPZ]|MS)/;
485 return function(format){
486 return hourInfoRe.test(format.replace(stripEscapeRe, ''));
490 <span id='Ext-Date-method-formatContainsDateInfo'> /**
491 </span> * Checks if the specified format contains information about
492 * anything other than the time.
493 * @param {String} format The format to check
494 * @return {Boolean} True if the format contains information about
495 * date/day information.
499 formatContainsDateInfo : (function(){
500 var stripEscapeRe = /(\\.)/g,
501 dateInfoRe = /([djzmnYycU]|MS)/;
503 return function(format){
504 return dateInfoRe.test(format.replace(stripEscapeRe, ''));
508 <span id='Ext-Date-property-formatCodes'> /**
509 </span> * The base format-code to formatting-function hashmap used by the {@link #format} method.
510 * Formatting functions are strings (or functions which return strings) which
511 * will return the appropriate value when evaluated in the context of the Date object
512 * from which the {@link #format} method is called.
513 * Add to / override these mappings for custom date formatting.
514 * Note: Ext.Date.format() treats characters as literals if an appropriate mapping cannot be found.
516 * <pre><code>
517 Ext.Date.formatCodes.x = "Ext.util.Format.leftPad(this.getDate(), 2, '0')";
518 console.log(Ext.Date.format(new Date(), 'X'); // returns the current day of the month
519 </code></pre>
524 d: "Ext.String.leftPad(this.getDate(), 2, '0')",
525 D: "Ext.Date.getShortDayName(this.getDay())", // get localised short day name
526 j: "this.getDate()",
527 l: "Ext.Date.dayNames[this.getDay()]",
528 N: "(this.getDay() ? this.getDay() : 7)",
529 S: "Ext.Date.getSuffix(this)",
530 w: "this.getDay()",
531 z: "Ext.Date.getDayOfYear(this)",
532 W: "Ext.String.leftPad(Ext.Date.getWeekOfYear(this), 2, '0')",
533 F: "Ext.Date.monthNames[this.getMonth()]",
534 m: "Ext.String.leftPad(this.getMonth() + 1, 2, '0')",
535 M: "Ext.Date.getShortMonthName(this.getMonth())", // get localised short month name
536 n: "(this.getMonth() + 1)",
537 t: "Ext.Date.getDaysInMonth(this)",
538 L: "(Ext.Date.isLeapYear(this) ? 1 : 0)",
539 o: "(this.getFullYear() + (Ext.Date.getWeekOfYear(this) == 1 && this.getMonth() > 0 ? +1 : (Ext.Date.getWeekOfYear(this) >= 52 && this.getMonth() < 11 ? -1 : 0)))",
540 Y: "Ext.String.leftPad(this.getFullYear(), 4, '0')",
541 y: "('' + this.getFullYear()).substring(2, 4)",
542 a: "(this.getHours() < 12 ? 'am' : 'pm')",
543 A: "(this.getHours() < 12 ? 'AM' : 'PM')",
544 g: "((this.getHours() % 12) ? this.getHours() % 12 : 12)",
545 G: "this.getHours()",
546 h: "Ext.String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')",
547 H: "Ext.String.leftPad(this.getHours(), 2, '0')",
548 i: "Ext.String.leftPad(this.getMinutes(), 2, '0')",
549 s: "Ext.String.leftPad(this.getSeconds(), 2, '0')",
550 u: "Ext.String.leftPad(this.getMilliseconds(), 3, '0')",
551 O: "Ext.Date.getGMTOffset(this)",
552 P: "Ext.Date.getGMTOffset(this, true)",
553 T: "Ext.Date.getTimezone(this)",
554 Z: "(this.getTimezoneOffset() * -60)",
556 c: function() { // ISO-8601 -- GMT format
557 for (var c = "Y-m-dTH:i:sP", code = [], i = 0, l = c.length; i < l; ++i) {
559 code.push(e == "T" ? "'T'" : utilDate.getFormatCode(e)); // treat T as a character literal
561 return code.join(" + ");
564 c: function() { // ISO-8601 -- UTC format
566 "this.getUTCFullYear()", "'-'",
567 "Ext.util.Format.leftPad(this.getUTCMonth() + 1, 2, '0')", "'-'",
568 "Ext.util.Format.leftPad(this.getUTCDate(), 2, '0')",
570 "Ext.util.Format.leftPad(this.getUTCHours(), 2, '0')", "':'",
571 "Ext.util.Format.leftPad(this.getUTCMinutes(), 2, '0')", "':'",
572 "Ext.util.Format.leftPad(this.getUTCSeconds(), 2, '0')",
574 ].join(" + ");
578 U: "Math.round(this.getTime() / 1000)"
581 <span id='Ext-Date-method-isValid'> /**
582 </span> * Checks if the passed Date parameters will cause a javascript Date "rollover".
583 * @param {Number} year 4-digit year
584 * @param {Number} month 1-based month-of-year
585 * @param {Number} day Day of month
586 * @param {Number} hour (optional) Hour
587 * @param {Number} minute (optional) Minute
588 * @param {Number} second (optional) Second
589 * @param {Number} millisecond (optional) Millisecond
590 * @return {Boolean} true if the passed parameters do not cause a Date "rollover", false otherwise.
593 isValid : function(y, m, d, h, i, s, ms) {
600 // Special handling for year < 100
601 var dt = utilDate.add(new Date(y < 100 ? 100 : y, m - 1, d, h, i, s, ms), utilDate.YEAR, y < 100 ? y - 100 : 0);
603 return y == dt.getFullYear() &&
604 m == dt.getMonth() + 1 &&
605 d == dt.getDate() &&
606 h == dt.getHours() &&
607 i == dt.getMinutes() &&
608 s == dt.getSeconds() &&
609 ms == dt.getMilliseconds();
612 <span id='Ext-Date-method-parse'> /**
613 </span> * Parses the passed string using the specified date format.
614 * Note that this function expects normal calendar dates, meaning that months are 1-based (i.e. 1 = January).
615 * The {@link #defaults} hash will be used for any date value (i.e. year, month, day, hour, minute, second or millisecond)
616 * which cannot be found in the passed string. If a corresponding default date value has not been specified in the {@link #defaults} hash,
617 * the current date's year, month, day or DST-adjusted zero-hour time value will be used instead.
618 * Keep in mind that the input date string must precisely match the specified format string
619 * in order for the parse operation to be successful (failed parse operations return a null value).
620 * <p>Example:</p><pre><code>
621 //dt = Fri May 25 2007 (current date)
624 //dt = Thu May 25 2006 (today&#39;s month/day in 2006)
625 dt = Ext.Date.parse("2006", "Y");
627 //dt = Sun Jan 15 2006 (all date parts specified)
628 dt = Ext.Date.parse("2006-01-15", "Y-m-d");
630 //dt = Sun Jan 15 2006 15:20:01
631 dt = Ext.Date.parse("2006-01-15 3:20:01 PM", "Y-m-d g:i:s A");
633 // attempt to parse Sun Feb 29 2006 03:20:01 in strict mode
634 dt = Ext.Date.parse("2006-02-29 03:20:01", "Y-m-d H:i:s", true); // returns null
635 </code></pre>
636 * @param {String} input The raw date string.
637 * @param {String} format The expected date string format.
638 * @param {Boolean} strict (optional) True to validate date strings while parsing (i.e. prevents javascript Date "rollover")
639 (defaults to false). Invalid date strings will return null when parsed.
640 * @return {Date} The parsed Date.
643 parse : function(input, format, strict) {
644 var p = utilDate.parseFunctions;
645 if (p[format] == null) {
646 utilDate.createParser(format);
648 return p[format](input, Ext.isDefined(strict) ? strict : utilDate.useStrict);
652 parseDate: function(input, format, strict){
653 return utilDate.parse(input, format, strict);
658 getFormatCode : function(character) {
659 var f = utilDate.formatCodes[character];
662 f = typeof f == 'function'? f() : f;
663 utilDate.formatCodes[character] = f; // reassign function result to prevent repeated execution
666 // note: unknown characters are treated as literals
667 return f || ("'" + Ext.String.escape(character) + "'");
671 createFormat : function(format) {
676 for (var i = 0; i < format.length; ++i) {
677 ch = format.charAt(i);
678 if (!special && ch == "\\") {
680 } else if (special) {
682 code.push("'" + Ext.String.escape(ch) + "'");
684 code.push(utilDate.getFormatCode(ch));
687 utilDate.formatFunctions[format] = Ext.functionFactory("return " + code.join('+'));
691 createParser : (function() {
693 "var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,",
694 "def = Ext.Date.defaults,",
695 "results = String(input).match(Ext.Date.parseRegexes[{0}]);", // either null, or an array of matched strings
697 "if(results){",
700 "if(u != null){", // i.e. unix time is defined
701 "v = new Date(u * 1000);", // give top priority to UNIX time
703 // create Date object representing midnight of the current day;
704 // this will provide us with our date defaults
705 // (note: clearTime() handles Daylight Saving Time automatically)
706 "dt = Ext.Date.clearTime(new Date);",
708 // date calculations (note: these calculations create a dependency on Ext.Number.from())
709 "y = Ext.Number.from(y, Ext.Number.from(def.y, dt.getFullYear()));",
710 "m = Ext.Number.from(m, Ext.Number.from(def.m - 1, dt.getMonth()));",
711 "d = Ext.Number.from(d, Ext.Number.from(def.d, dt.getDate()));",
713 // time calculations (note: these calculations create a dependency on Ext.Number.from())
714 "h = Ext.Number.from(h, Ext.Number.from(def.h, dt.getHours()));",
715 "i = Ext.Number.from(i, Ext.Number.from(def.i, dt.getMinutes()));",
716 "s = Ext.Number.from(s, Ext.Number.from(def.s, dt.getSeconds()));",
717 "ms = Ext.Number.from(ms, Ext.Number.from(def.ms, dt.getMilliseconds()));",
719 "if(z >= 0 && y >= 0){",
720 // both the year and zero-based day of year are defined and >= 0.
721 // these 2 values alone provide sufficient info to create a full date object
723 // create Date object representing January 1st for the given year
724 // handle years < 100 appropriately
725 "v = Ext.Date.add(new Date(y < 100 ? 100 : y, 0, 1, h, i, s, ms), Ext.Date.YEAR, y < 100 ? y - 100 : 0);",
727 // then add day of year, checking for Date "rollover" if necessary
728 "v = !strict? v : (strict === true && (z <= 364 || (Ext.Date.isLeapYear(v) && z <= 365))? Ext.Date.add(v, Ext.Date.DAY, z) : null);",
729 "}else if(strict === true && !Ext.Date.isValid(y, m + 1, d, h, i, s, ms)){", // check for Date "rollover"
730 "v = null;", // invalid date, so return null
732 // plain old Date object
733 // handle years < 100 properly
734 "v = Ext.Date.add(new Date(y < 100 ? 100 : y, m, d, h, i, s, ms), Ext.Date.YEAR, y < 100 ? y - 100 : 0);",
740 // favour UTC offset over GMT offset
741 "if(zz != null){",
742 // reset to UTC, then add offset
743 "v = Ext.Date.add(v, Ext.Date.SECOND, -v.getTimezoneOffset() * 60 - zz);",
744 "}else if(o){",
745 // reset to GMT, then add offset
746 "v = Ext.Date.add(v, Ext.Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn));",
750 "return v;"
753 return function(format) {
754 var regexNum = utilDate.parseRegexes.length,
761 for (var i = 0; i < format.length; ++i) {
762 ch = format.charAt(i);
763 if (!special && ch == "\\") {
765 } else if (special) {
767 regex.push(Ext.String.escape(ch));
769 var obj = utilDate.formatCodeToRegex(ch, currentGroup);
770 currentGroup += obj.g;
772 if (obj.g && obj.c) {
778 utilDate.parseRegexes[regexNum] = new RegExp("^" + regex.join('') + "$", 'i');
779 utilDate.parseFunctions[format] = Ext.functionFactory("input", "strict", xf(code, regexNum, calc.join('')));
787 * g = {Number} calculation group (0 or 1. only group 1 contributes to date calculations.)
788 * c = {String} calculation method (required for group 1. null for group 0. {0} = currentGroup - position in regex result array)
789 * s = {String} regex pattern. all matches are stored in results[], and are accessible by the calculation mapped to 'c'
793 c:"d = parseInt(results[{0}], 10);\n",
794 s:"(\\d{2})" // day of month with leading zeroes (01 - 31)
798 c:"d = parseInt(results[{0}], 10);\n",
799 s:"(\\d{1,2})" // day of month without leading zeroes (1 - 31)
802 for (var a = [], i = 0; i < 7; a.push(utilDate.getShortDayName(i)), ++i); // get localised short day names
806 s:"(?:" + a.join("|") +")"
813 s:"(?:" + utilDate.dayNames.join("|") + ")"
819 s:"[1-7]" // ISO-8601 day number (1 (monday) - 7 (sunday))
824 s:"(?:st|nd|rd|th)"
829 s:"[0-6]" // javascript day number (0 (sunday) - 6 (saturday))
833 c:"z = parseInt(results[{0}], 10);\n",
834 s:"(\\d{1,3})" // day of the year (0 - 364 (365 in leap years))
839 s:"(?:\\d{2})" // ISO-8601 week number (with leading zero)
844 c:"m = parseInt(Ext.Date.getMonthNumber(results[{0}]), 10);\n", // get localised month number
845 s:"(" + utilDate.monthNames.join("|") + ")"
849 for (var a = [], i = 0; i < 12; a.push(utilDate.getShortMonthName(i)), ++i); // get localised short month names
851 s:"(" + a.join("|") + ")"
852 }, utilDate.formatCodeToRegex("F"));
856 c:"m = parseInt(results[{0}], 10) - 1;\n",
857 s:"(\\d{2})" // month number with leading zeros (01 - 12)
861 c:"m = parseInt(results[{0}], 10) - 1;\n",
862 s:"(\\d{1,2})" // month number without leading zeros (1 - 12)
867 s:"(?:\\d{2})" // no. of days in the month (28 - 31)
872 s:"(?:1|0)"
875 return utilDate.formatCodeToRegex("Y");
879 c:"y = parseInt(results[{0}], 10);\n",
880 s:"(\\d{4})" // 4-digit year
884 c:"var ty = parseInt(results[{0}], 10);\n"
885 + "y = ty > Ext.Date.y2kYear ? 1900 + ty : 2000 + ty;\n", // 2-digit year
886 s:"(\\d{1,2})"
889 * In the am/pm parsing routines, we allow both upper and lower case
890 * even though it doesn't exactly match the spec. It gives much more flexibility
891 * in being able to specify case insensitive regexes.
895 c:"if (/(am)/i.test(results[{0}])) {\n"
896 + "if (!h || h == 12) { h = 0; }\n"
897 + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
898 s:"(am|pm|AM|PM)"
902 c:"if (/(am)/i.test(results[{0}])) {\n"
903 + "if (!h || h == 12) { h = 0; }\n"
904 + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
905 s:"(AM|PM|am|pm)"
908 return utilDate.formatCodeToRegex("G");
912 c:"h = parseInt(results[{0}], 10);\n",
913 s:"(\\d{1,2})" // 24-hr format of an hour without leading zeroes (0 - 23)
916 return utilDate.formatCodeToRegex("H");
920 c:"h = parseInt(results[{0}], 10);\n",
921 s:"(\\d{2})" // 24-hr format of an hour with leading zeroes (00 - 23)
925 c:"i = parseInt(results[{0}], 10);\n",
926 s:"(\\d{2})" // minutes with leading zeros (00 - 59)
930 c:"s = parseInt(results[{0}], 10);\n",
931 s:"(\\d{2})" // seconds with leading zeros (00 - 59)
935 c:"ms = results[{0}]; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n",
936 s:"(\\d+)" // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
941 "o = results[{0}];",
942 "var sn = o.substring(0,1),", // get + / - sign
943 "hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
944 "mn = o.substring(3,5) % 60;", // get minutes
945 "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
946 ].join("\n"),
947 s: "([+\-]\\d{4})" // GMT offset in hrs and mins
952 "o = results[{0}];",
953 "var sn = o.substring(0,1),", // get + / - sign
954 "hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
955 "mn = o.substring(4,6) % 60;", // get minutes
956 "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
957 ].join("\n"),
958 s: "([+\-]\\d{2}:\\d{2})" // GMT offset in hrs and mins (with colon separator)
963 s:"[A-Z]{1,4}" // timezone abbrev. may be between 1 - 4 chars
967 c:"zz = results[{0}] * 1;\n" // -43200 <= UTC offset <= 50400
968 + "zz = (-43200 <= zz && zz <= 50400)? zz : null;\n",
969 s:"([+\-]?\\d{1,5})" // leading '+' sign is optional for UTC offset
974 utilDate.formatCodeToRegex("Y", 1), // year
975 utilDate.formatCodeToRegex("m", 2), // month
976 utilDate.formatCodeToRegex("d", 3), // day
977 utilDate.formatCodeToRegex("h", 4), // hour
978 utilDate.formatCodeToRegex("i", 5), // minute
979 utilDate.formatCodeToRegex("s", 6), // second
980 {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)
981 {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
982 "if(results[8]) {", // timezone specified
983 "if(results[8] == 'Z'){",
984 "zz = 0;", // UTC
985 "}else if (results[8].indexOf(':') > -1){",
986 utilDate.formatCodeToRegex("P", 8).c, // timezone offset with colon separator
988 utilDate.formatCodeToRegex("O", 8).c, // timezone offset without colon separator
994 for (var i = 0, l = arr.length; i < l; ++i) {
1000 c:calc.join(""),
1002 arr[0].s, // year (required)
1003 "(?:", "-", arr[1].s, // month (optional)
1004 "(?:", "-", arr[2].s, // day (optional)
1006 "(?:T| )?", // time delimiter -- either a "T" or a single blank space
1007 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
1008 "(?::", arr[5].s, ")?", // seconds (optional)
1009 "(?:(?:\\.|,)(\\d+))?", // decimal fraction of a second (e.g. ",12345" or ".98765") (optional)
1010 "(Z|(?:[-+]\\d{2}(?::)?\\d{2}))?", // "Z" (UTC) or "-0530" (UTC offset without colon delimiter) or "+08:00" (UTC offset with colon delimiter) (optional)
1014 ].join("")
1019 c:"u = parseInt(results[{0}], 10);\n",
1020 s:"(-?\\d+)" // leading minus sign indicates seconds before UNIX epoch
1024 //Old Ext.Date prototype methods.
1026 dateFormat: function(date, format) {
1027 return utilDate.format(date, format);
1030 <span id='Ext-Date-method-format'> /**
1031 </span> * Formats a date given the supplied format string.
1032 * @param {Date} date The date to format
1033 * @param {String} format The format string
1034 * @return {String} The formatted date
1036 format: function(date, format) {
1037 if (utilDate.formatFunctions[format] == null) {
1038 utilDate.createFormat(format);
1040 var result = utilDate.formatFunctions[format].call(date);
1044 <span id='Ext-Date-method-getTimezone'> /**
1045 </span> * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
1047 * Note: The date string returned by the javascript Date object's toString() method varies
1048 * between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America).
1049 * For a given date string e.g. "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)",
1050 * getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses
1051 * (which may or may not be present), failing which it proceeds to get the timezone abbreviation
1052 * from the GMT offset portion of the date string.
1053 * @param {Date} date The date
1054 * @return {String} The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).
1056 getTimezone : function(date) {
1057 // the following list shows the differences between date strings from different browsers on a WinXP SP2 machine from an Asian locale:
1059 // Opera : "Thu, 25 Oct 2007 22:53:45 GMT+0800" -- shortest (weirdest) date string of the lot
1060 // 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)
1061 // FF : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone
1062 // IE : "Thu Oct 25 22:54:35 UTC+0800 2007" -- (Asian system setting) look for 3-4 letter timezone abbrev
1063 // IE : "Thu Oct 25 17:06:37 PDT 2007" -- (American system setting) look for 3-4 letter timezone abbrev
1065 // this crazy regex attempts to guess the correct timezone abbreviation despite these differences.
1066 // step 1: (?:\((.*)\) -- find timezone in parentheses
1067 // 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
1068 // step 3: remove all non uppercase characters found in step 1 and 2
1069 return date.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, "");
1072 <span id='Ext-Date-method-getGMTOffset'> /**
1073 </span> * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
1074 * @param {Date} date The date
1075 * @param {Boolean} colon (optional) true to separate the hours and minutes with a colon (defaults to false).
1076 * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600').
1078 getGMTOffset : function(date, colon) {
1079 var offset = date.getTimezoneOffset();
1080 return (offset > 0 ? "-" : "+")
1081 + Ext.String.leftPad(Math.floor(Math.abs(offset) / 60), 2, "0")
1082 + (colon ? ":" : "")
1083 + Ext.String.leftPad(Math.abs(offset % 60), 2, "0");
1086 <span id='Ext-Date-method-getDayOfYear'> /**
1087 </span> * Get the numeric day number of the year, adjusted for leap year.
1088 * @param {Date} date The date
1089 * @return {Number} 0 to 364 (365 in leap years).
1091 getDayOfYear: function(date) {
1093 d = Ext.Date.clone(date),
1094 m = date.getMonth(),
1097 for (i = 0, d.setDate(1), d.setMonth(0); i < m; d.setMonth(++i)) {
1098 num += utilDate.getDaysInMonth(d);
1100 return num + date.getDate() - 1;
1103 <span id='Ext-Date-method-getWeekOfYear'> /**
1104 </span> * Get the numeric ISO-8601 week number of the year.
1105 * (equivalent to the format specifier 'W', but without a leading zero).
1106 * @param {Date} date The date
1107 * @return {Number} 1 to 53
1110 getWeekOfYear : (function() {
1111 // adapted from http://www.merlyn.demon.co.uk/weekcalc.htm
1112 var ms1d = 864e5, // milliseconds in a day
1113 ms7d = 7 * ms1d; // milliseconds in a week
1115 return function(date) { // return a closure so constants get calculated only once
1116 var DC3 = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate() + 3) / ms1d, // an Absolute Day Number
1117 AWN = Math.floor(DC3 / 7), // an Absolute Week Number
1118 Wyr = new Date(AWN * ms7d).getUTCFullYear();
1120 return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
1124 <span id='Ext-Date-method-isLeapYear'> /**
1125 </span> * Checks if the current date falls within a leap year.
1126 * @param {Date} date The date
1127 * @return {Boolean} True if the current date falls within a leap year, false otherwise.
1129 isLeapYear : function(date) {
1130 var year = date.getFullYear();
1131 return !!((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
1134 <span id='Ext-Date-method-getFirstDayOfMonth'> /**
1135 </span> * Get the first day of the current month, adjusted for leap year. The returned value
1136 * is the numeric day index within the week (0-6) which can be used in conjunction with
1137 * the {@link #monthNames} array to retrieve the textual day name.
1139 * <pre><code>
1140 var dt = new Date('1/10/2007'),
1141 firstDay = Ext.Date.getFirstDayOfMonth(dt);
1142 console.log(Ext.Date.dayNames[firstDay]); //output: 'Monday'
1143 * </code></pre>
1144 * @param {Date} date The date
1145 * @return {Number} The day number (0-6).
1147 getFirstDayOfMonth : function(date) {
1148 var day = (date.getDay() - (date.getDate() - 1)) % 7;
1149 return (day < 0) ? (day + 7) : day;
1152 <span id='Ext-Date-method-getLastDayOfMonth'> /**
1153 </span> * Get the last day of the current month, adjusted for leap year. The returned value
1154 * is the numeric day index within the week (0-6) which can be used in conjunction with
1155 * the {@link #monthNames} array to retrieve the textual day name.
1157 * <pre><code>
1158 var dt = new Date('1/10/2007'),
1159 lastDay = Ext.Date.getLastDayOfMonth(dt);
1160 console.log(Ext.Date.dayNames[lastDay]); //output: 'Wednesday'
1161 * </code></pre>
1162 * @param {Date} date The date
1163 * @return {Number} The day number (0-6).
1165 getLastDayOfMonth : function(date) {
1166 return utilDate.getLastDateOfMonth(date).getDay();
1170 <span id='Ext-Date-method-getFirstDateOfMonth'> /**
1171 </span> * Get the date of the first day of the month in which this date resides.
1172 * @param {Date} date The date
1175 getFirstDateOfMonth : function(date) {
1176 return new Date(date.getFullYear(), date.getMonth(), 1);
1179 <span id='Ext-Date-method-getLastDateOfMonth'> /**
1180 </span> * Get the date of the last day of the month in which this date resides.
1181 * @param {Date} date The date
1184 getLastDateOfMonth : function(date) {
1185 return new Date(date.getFullYear(), date.getMonth(), utilDate.getDaysInMonth(date));
1188 <span id='Ext-Date-method-getDaysInMonth'> /**
1189 </span> * Get the number of days in the current month, adjusted for leap year.
1190 * @param {Date} date The date
1191 * @return {Number} The number of days in the month.
1194 getDaysInMonth: (function() {
1195 var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
1197 return function(date) { // return a closure for efficiency
1198 var m = date.getMonth();
1200 return m == 1 && utilDate.isLeapYear(date) ? 29 : daysInMonth[m];
1204 <span id='Ext-Date-method-getSuffix'> /**
1205 </span> * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
1206 * @param {Date} date The date
1207 * @return {String} 'st, 'nd', 'rd' or 'th'.
1209 getSuffix : function(date) {
1210 switch (date.getDate()) {
1214 return "st";
1217 return "nd";
1220 return "rd";
1222 return "th";
1226 <span id='Ext-Date-method-clone'> /**
1227 </span> * Creates and returns a new Date instance with the exact same date value as the called instance.
1228 * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
1229 * variable will also be changed. When the intention is to create a new variable that will not
1230 * modify the original instance, you should create a clone.
1232 * Example of correctly cloning a date:
1233 * <pre><code>
1235 var orig = new Date('10/1/2006');
1238 console.log(orig); //returns 'Thu Oct 05 2006'!
1241 var orig = new Date('10/1/2006'),
1242 copy = Ext.Date.clone(orig);
1244 console.log(orig); //returns 'Thu Oct 01 2006'
1245 * </code></pre>
1246 * @param {Date} date The date
1247 * @return {Date} The new Date instance.
1249 clone : function(date) {
1250 return new Date(date.getTime());
1253 <span id='Ext-Date-method-isDST'> /**
1254 </span> * Checks if the current date is affected by Daylight Saving Time (DST).
1255 * @param {Date} date The date
1256 * @return {Boolean} True if the current date is affected by DST.
1258 isDST : function(date) {
1259 // adapted from http://sencha.com/forum/showthread.php?p=247172#post247172
1260 // courtesy of @geoffrey.mcgill
1261 return new Date(date.getFullYear(), 0, 1).getTimezoneOffset() != date.getTimezoneOffset();
1264 <span id='Ext-Date-method-clearTime'> /**
1265 </span> * Attempts to clear all time information from this Date by setting the time to midnight of the same day,
1266 * automatically adjusting for Daylight Saving Time (DST) where applicable.
1267 * (note: DST timezone information for the browser's host operating system is assumed to be up-to-date)
1268 * @param {Date} date The date
1269 * @param {Boolean} clone true to create a clone of this date, clear the time and return it (defaults to false).
1270 * @return {Date} this or the clone.
1272 clearTime : function(date, clone) {
1274 return Ext.Date.clearTime(Ext.Date.clone(date));
1277 // get current date before clearing time
1278 var d = date.getDate();
1284 date.setMilliseconds(0);
1286 if (date.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
1287 // note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the case)
1288 // refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
1290 // increment hour until cloned date == current date
1291 for (var hr = 1, c = utilDate.add(date, Ext.Date.HOUR, hr); c.getDate() != d; hr++, c = utilDate.add(date, Ext.Date.HOUR, hr));
1294 date.setHours(c.getHours());
1300 <span id='Ext-Date-method-add'> /**
1301 </span> * Provides a convenient method for performing basic date arithmetic. This method
1302 * does not modify the Date instance being called - it creates and returns
1303 * a new Date instance containing the resulting date value.
1306 * <pre><code>
1308 var dt = Ext.Date.add(new Date('10/29/2006'), Ext.Date.DAY, 5);
1309 console.log(dt); //returns 'Fri Nov 03 2006 00:00:00'
1311 // Negative values will be subtracted:
1312 var dt2 = Ext.Date.add(new Date('10/1/2006'), Ext.Date.DAY, -5);
1313 console.log(dt2); //returns 'Tue Sep 26 2006 00:00:00'
1315 * </code></pre>
1317 * @param {Date} date The date to modify
1318 * @param {String} interval A valid date interval enum value.
1319 * @param {Number} value The amount to add to the current date.
1320 * @return {Date} The new Date instance.
1322 add : function(date, interval, value) {
1323 var d = Ext.Date.clone(date),
1325 if (!interval || value === 0) return d;
1327 switch(interval.toLowerCase()) {
1328 case Ext.Date.MILLI:
1329 d.setMilliseconds(d.getMilliseconds() + value);
1331 case Ext.Date.SECOND:
1332 d.setSeconds(d.getSeconds() + value);
1334 case Ext.Date.MINUTE:
1335 d.setMinutes(d.getMinutes() + value);
1338 d.setHours(d.getHours() + value);
1341 d.setDate(d.getDate() + value);
1343 case Ext.Date.MONTH:
1344 var day = date.getDate();
1346 day = Math.min(day, Ext.Date.getLastDateOfMonth(Ext.Date.add(Ext.Date.getFirstDateOfMonth(date), 'mo', value)).getDate());
1349 d.setMonth(date.getMonth() + value);
1352 d.setFullYear(date.getFullYear() + value);
1358 <span id='Ext-Date-method-between'> /**
1359 </span> * Checks if a date falls on or between the given start and end dates.
1360 * @param {Date} date The date to check
1361 * @param {Date} start Start date
1362 * @param {Date} end End date
1363 * @return {Boolean} true if this date falls on or between the given start and end dates.
1365 between : function(date, start, end) {
1366 var t = date.getTime();
1367 return start.getTime() <= t && t <= end.getTime();
1370 //Maintains compatibility with old static and prototype window.Date methods.
1371 compat: function() {
1372 var nativeDate = window.Date,
1374 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'],
1375 proto = ['dateFormat', 'format', 'getTimezone', 'getGMTOffset', 'getDayOfYear', 'getWeekOfYear', 'isLeapYear', 'getFirstDayOfMonth', 'getLastDayOfMonth', 'getDaysInMonth', 'getSuffix', 'clone', 'isDST', 'clearTime', 'add', 'between'];
1378 Ext.Array.forEach(statics, function(s) {
1379 nativeDate[s] = utilDate[s];
1382 //Append to prototype
1383 Ext.Array.forEach(proto, function(s) {
1384 nativeDate.prototype[s] = function() {
1385 var args = Array.prototype.slice.call(arguments);
1387 return utilDate[s].apply(utilDate, args);
1393 var utilDate = Ext.Date;