Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / source / Date4.html
1 <!DOCTYPE html>
2 <html>
3 <head>
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; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
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
23  *
24  * The date parsing and formatting syntax contains a subset of
25  * &lt;a href=&quot;http://www.php.net/date&quot;&gt;PHP's date() function&lt;/a&gt;, and the formats that are
26  * supported will provide results equivalent to their PHP versions.
27  *
28  * The following is a list of all currently supported formats:
29  * &lt;pre class=&quot;&quot;&gt;
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&amp;#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
61                                                                                   100 (i.e. 0.100s) or
62                                                                                   999 (i.e. 0.999s) 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
68   c     ISO 8601 date
69         Notes:                                                                    Examples:
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 &quot;T&quot; 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)\/
84 &lt;/pre&gt;
85  *
86  * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
87  * &lt;pre&gt;&lt;code&gt;
88 // Sample date:
89 // 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
90
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 &lt;/code&gt;&lt;/pre&gt;
96  *
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  * &lt;pre&gt;&lt;code&gt;
102 Ext.Date.patterns = {
103     ISO8601Long:&quot;Y-m-d H:i:s&quot;,
104     ISO8601Short:&quot;Y-m-d&quot;,
105     ShortDate: &quot;n/j/Y&quot;,
106     LongDate: &quot;l, F d, Y&quot;,
107     FullDateTime: &quot;l, F d, Y g:i:s A&quot;,
108     MonthDay: &quot;F d&quot;,
109     ShortTime: &quot;g:i A&quot;,
110     LongTime: &quot;g:i:s A&quot;,
111     SortableDateTime: &quot;Y-m-d\\TH:i:s&quot;,
112     UniversalSortableDateTime: &quot;Y-m-d H:i:sO&quot;,
113     YearMonth: &quot;F, Y&quot;
114 };
115 &lt;/code&gt;&lt;/pre&gt;
116  *
117  * Example usage:
118  * &lt;pre&gt;&lt;code&gt;
119 var dt = new Date();
120 console.log(Ext.Date.format(dt, Ext.Date.patterns.ShortDate));
121 &lt;/code&gt;&lt;/pre&gt;
122  * &lt;p&gt;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}.&lt;/p&gt;
124  * @singleton
125  */
126
127 /*
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.
133  */
134
135 (function() {
136
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) {
143         return args[i];
144     });
145 }
146
147 Ext.Date = {
148 <span id='Ext-Date-method-now'>    /**
149 </span>     * Returns the current timestamp
150      * @return {Date} The current timestamp
151      * @method
152      */
153     now: Date.now || function() {
154         return +new Date();
155     },
156
157 <span id='Ext-Date-method-toString'>    /**
158 </span>     * @private
159      * Private for now
160      */
161     toString: function(date) {
162         var pad = Ext.String.leftPad;
163
164         return date.getFullYear() + &quot;-&quot;
165             + pad(date.getMonth() + 1, 2, '0') + &quot;-&quot;
166             + pad(date.getDate(), 2, '0') + &quot;T&quot;
167             + pad(date.getHours(), 2, '0') + &quot;:&quot;
168             + pad(date.getMinutes(), 2, '0') + &quot;:&quot;
169             + pad(date.getSeconds(), 2, '0');
170     },
171
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
177      */
178     getElapsed: function(dateA, dateB) {
179         return Math.abs(dateA - (dateB || new Date()));
180     },
181
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 &lt;tt&gt;false&lt;/tt&gt;.
188      * @static
189      * @type Boolean
190     */
191     useStrict: false,
192
193     // private
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];
197
198         if (p) {
199           p = typeof p == 'function'? p() : p;
200           utilDate.parseCodes[character] = p; // reassign function result to prevent repeated execution
201         }
202
203         return p ? Ext.applyIf({
204           c: p.c ? xf(p.c, currentGroup || &quot;{0}&quot;) : p.c
205         }, p) : {
206             g: 0,
207             c: null,
208             s: Ext.String.escapeRegex(character) // treat unrecognised characters as literals
209         };
210     },
211
212 <span id='Ext-Date-property-parseFunctions'>    /**
213 </span>     * &lt;p&gt;An object hash in which each property is a date parsing function. The property name is the
214      * format string which that function parses.&lt;/p&gt;
215      * &lt;p&gt;This object is automatically populated with date parsing functions as
216      * date formats are requested for Ext standard formatting strings.&lt;/p&gt;
217      * &lt;p&gt;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}.&lt;p&gt;
219      * &lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
220 Ext.Date.parseFunctions['x-date-format'] = myDateParser;
221 &lt;/code&gt;&lt;/pre&gt;
222      * &lt;p&gt;A parsing function should return a Date object, and is passed the following parameters:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
223      * &lt;li&gt;&lt;code&gt;date&lt;/code&gt; : String&lt;div class=&quot;sub-desc&quot;&gt;The date string to parse.&lt;/div&gt;&lt;/li&gt;
224      * &lt;li&gt;&lt;code&gt;strict&lt;/code&gt; : Boolean&lt;div class=&quot;sub-desc&quot;&gt;True to validate date strings while parsing
225      * (i.e. prevent javascript Date &quot;rollover&quot;) (The default must be false).
226      * Invalid date strings should return null when parsed.&lt;/div&gt;&lt;/li&gt;
227      * &lt;/ul&gt;&lt;/div&gt;&lt;/p&gt;
228      * &lt;p&gt;To enable Dates to also be &lt;i&gt;formatted&lt;/i&gt; according to that format, a corresponding
229      * formatting function must be placed into the {@link #formatFunctions} property.
230      * @property parseFunctions
231      * @static
232      * @type Object
233      */
234     parseFunctions: {
235         &quot;MS&quot;: 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;
241         }
242     },
243     parseRegexes: [],
244
245 <span id='Ext-Date-property-formatFunctions'>    /**
246 </span>     * &lt;p&gt;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.&lt;/p&gt;
248      * &lt;p&gt;This object is automatically populated with date formatting functions as
249      * date formats are requested for Ext standard formatting strings.&lt;/p&gt;
250      * &lt;p&gt;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:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
252 Ext.Date.formatFunctions['x-date-format'] = myDateFormatter;
253 &lt;/code&gt;&lt;/pre&gt;
254      * &lt;p&gt;A formatting function should return a string representation of the passed Date object, and is passed the following parameters:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
255      * &lt;li&gt;&lt;code&gt;date&lt;/code&gt; : Date&lt;div class=&quot;sub-desc&quot;&gt;The Date to format.&lt;/div&gt;&lt;/li&gt;
256      * &lt;/ul&gt;&lt;/div&gt;&lt;/p&gt;
257      * &lt;p&gt;To enable date strings to also be &lt;i&gt;parsed&lt;/i&gt; according to that format, a corresponding
258      * parsing function must be placed into the {@link #parseFunctions} property.
259      * @property formatFunctions
260      * @static
261      * @type Object
262      */
263     formatFunctions: {
264         &quot;MS&quot;: function() {
265             // UTC milliseconds since Unix epoch (MS-AJAX serialized date format (MRSF))
266             return '\\/Date(' + this.getTime() + ')\\/';
267         }
268     },
269
270     y2kYear : 50,
271
272 <span id='Ext-Date-property-MILLI'>    /**
273 </span>     * Date interval constant
274      * @static
275      * @type String
276      */
277     MILLI : &quot;ms&quot;,
278
279 <span id='Ext-Date-property-SECOND'>    /**
280 </span>     * Date interval constant
281      * @static
282      * @type String
283      */
284     SECOND : &quot;s&quot;,
285
286 <span id='Ext-Date-property-MINUTE'>    /**
287 </span>     * Date interval constant
288      * @static
289      * @type String
290      */
291     MINUTE : &quot;mi&quot;,
292
293 <span id='Ext-Date-property-HOUR'>    /** Date interval constant
294 </span>     * @static
295      * @type String
296      */
297     HOUR : &quot;h&quot;,
298
299 <span id='Ext-Date-property-DAY'>    /**
300 </span>     * Date interval constant
301      * @static
302      * @type String
303      */
304     DAY : &quot;d&quot;,
305
306 <span id='Ext-Date-property-MONTH'>    /**
307 </span>     * Date interval constant
308      * @static
309      * @type String
310      */
311     MONTH : &quot;mo&quot;,
312
313 <span id='Ext-Date-property-YEAR'>    /**
314 </span>     * Date interval constant
315      * @static
316      * @type String
317      */
318     YEAR : &quot;y&quot;,
319
320 <span id='Ext-Date-property-defaults'>    /**
321 </span>     * &lt;p&gt;An object hash containing default date values used during date parsing.&lt;/p&gt;
322      * &lt;p&gt;The following properties are available:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
323      * &lt;li&gt;&lt;code&gt;y&lt;/code&gt; : Number&lt;div class=&quot;sub-desc&quot;&gt;The default year value. (defaults to undefined)&lt;/div&gt;&lt;/li&gt;
324      * &lt;li&gt;&lt;code&gt;m&lt;/code&gt; : Number&lt;div class=&quot;sub-desc&quot;&gt;The default 1-based month value. (defaults to undefined)&lt;/div&gt;&lt;/li&gt;
325      * &lt;li&gt;&lt;code&gt;d&lt;/code&gt; : Number&lt;div class=&quot;sub-desc&quot;&gt;The default day value. (defaults to undefined)&lt;/div&gt;&lt;/li&gt;
326      * &lt;li&gt;&lt;code&gt;h&lt;/code&gt; : Number&lt;div class=&quot;sub-desc&quot;&gt;The default hour value. (defaults to undefined)&lt;/div&gt;&lt;/li&gt;
327      * &lt;li&gt;&lt;code&gt;i&lt;/code&gt; : Number&lt;div class=&quot;sub-desc&quot;&gt;The default minute value. (defaults to undefined)&lt;/div&gt;&lt;/li&gt;
328      * &lt;li&gt;&lt;code&gt;s&lt;/code&gt; : Number&lt;div class=&quot;sub-desc&quot;&gt;The default second value. (defaults to undefined)&lt;/div&gt;&lt;/li&gt;
329      * &lt;li&gt;&lt;code&gt;ms&lt;/code&gt; : Number&lt;div class=&quot;sub-desc&quot;&gt;The default millisecond value. (defaults to undefined)&lt;/div&gt;&lt;/li&gt;
330      * &lt;/ul&gt;&lt;/div&gt;&lt;/p&gt;
331      * &lt;p&gt;Override these properties to customize the default date values used by the {@link #parse} method.&lt;/p&gt;
332      * &lt;p&gt;&lt;b&gt;Note: In countries which experience Daylight Saving Time (i.e. DST), the &lt;tt&gt;h&lt;/tt&gt;, &lt;tt&gt;i&lt;/tt&gt;, &lt;tt&gt;s&lt;/tt&gt;
333      * and &lt;tt&gt;ms&lt;/tt&gt; properties may coincide with the exact time in which DST takes effect.
334      * It is the responsiblity of the developer to account for this.&lt;/b&gt;&lt;/p&gt;
335      * Example Usage:
336      * &lt;pre&gt;&lt;code&gt;
337 // set default day value to the first day of the month
338 Ext.Date.defaults.d = 1;
339
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 &lt;/code&gt;&lt;/pre&gt;
345      * @property defaults
346      * @static
347      * @type Object
348      */
349     defaults: {},
350
351 <span id='Ext-Date-property-dayNames'>    /**
352 </span>     * An array of textual day names.
353      * Override these values for international dates.
354      * Example:
355      * &lt;pre&gt;&lt;code&gt;
356 Ext.Date.dayNames = [
357     'SundayInYourLang',
358     'MondayInYourLang',
359     ...
360 ];
361 &lt;/code&gt;&lt;/pre&gt;
362      * @type Array
363      * @static
364      */
365     dayNames : [
366         &quot;Sunday&quot;,
367         &quot;Monday&quot;,
368         &quot;Tuesday&quot;,
369         &quot;Wednesday&quot;,
370         &quot;Thursday&quot;,
371         &quot;Friday&quot;,
372         &quot;Saturday&quot;
373     ],
374
375 <span id='Ext-Date-property-monthNames'>    /**
376 </span>     * An array of textual month names.
377      * Override these values for international dates.
378      * Example:
379      * &lt;pre&gt;&lt;code&gt;
380 Ext.Date.monthNames = [
381     'JanInYourLang',
382     'FebInYourLang',
383     ...
384 ];
385 &lt;/code&gt;&lt;/pre&gt;
386      * @type Array
387      * @static
388      */
389     monthNames : [
390         &quot;January&quot;,
391         &quot;February&quot;,
392         &quot;March&quot;,
393         &quot;April&quot;,
394         &quot;May&quot;,
395         &quot;June&quot;,
396         &quot;July&quot;,
397         &quot;August&quot;,
398         &quot;September&quot;,
399         &quot;October&quot;,
400         &quot;November&quot;,
401         &quot;December&quot;
402     ],
403
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.
407      * Example:
408      * &lt;pre&gt;&lt;code&gt;
409 Ext.Date.monthNumbers = {
410     'ShortJanNameInYourLang':0,
411     'ShortFebNameInYourLang':1,
412     ...
413 };
414 &lt;/code&gt;&lt;/pre&gt;
415      * @type Object
416      * @static
417      */
418     monthNumbers : {
419         Jan:0,
420         Feb:1,
421         Mar:2,
422         Apr:3,
423         May:4,
424         Jun:5,
425         Jul:6,
426         Aug:7,
427         Sep:8,
428         Oct:9,
429         Nov:10,
430         Dec:11
431     },
432 <span id='Ext-Date-property-defaultFormat'>    /**
433 </span>     * &lt;p&gt;The date format string that the {@link Ext.util.Format#dateRenderer}
434      * and {@link Ext.util.Format#date} functions use.  See {@link Ext.Date} for details.&lt;/p&gt;
435      * &lt;p&gt;This defaults to &lt;code&gt;m/d/Y&lt;/code&gt;, but may be overridden in a locale file.&lt;/p&gt;
436      * @property defaultFormat
437      * @static
438      * @type String
439      */
440     defaultFormat : &quot;m/d/Y&quot;,
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.
446      * @static
447      */
448     getShortMonthName : function(month) {
449         return utilDate.monthNames[month].substring(0, 3);
450     },
451
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.
457      * @static
458      */
459     getShortDayName : function(day) {
460         return utilDate.dayNames[day].substring(0, 3);
461     },
462
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.
468      * @static
469      */
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()];
473     },
474
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
479      * @static
480      * @method
481      */
482     formatContainsHourInfo : (function(){
483         var stripEscapeRe = /(\\.)/g,
484             hourInfoRe = /([gGhHisucUOPZ]|MS)/;
485         return function(format){
486             return hourInfoRe.test(format.replace(stripEscapeRe, ''));
487         };
488     })(),
489
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.
496      * @static
497      * @method
498      */
499     formatContainsDateInfo : (function(){
500         var stripEscapeRe = /(\\.)/g,
501             dateInfoRe = /([djzmnYycU]|MS)/;
502
503         return function(format){
504             return dateInfoRe.test(format.replace(stripEscapeRe, ''));
505         };
506     })(),
507
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.
515      * Example:
516      * &lt;pre&gt;&lt;code&gt;
517 Ext.Date.formatCodes.x = &quot;Ext.util.Format.leftPad(this.getDate(), 2, '0')&quot;;
518 console.log(Ext.Date.format(new Date(), 'X'); // returns the current day of the month
519 &lt;/code&gt;&lt;/pre&gt;
520      * @type Object
521      * @static
522      */
523     formatCodes : {
524         d: &quot;Ext.String.leftPad(this.getDate(), 2, '0')&quot;,
525         D: &quot;Ext.Date.getShortDayName(this.getDay())&quot;, // get localised short day name
526         j: &quot;this.getDate()&quot;,
527         l: &quot;Ext.Date.dayNames[this.getDay()]&quot;,
528         N: &quot;(this.getDay() ? this.getDay() : 7)&quot;,
529         S: &quot;Ext.Date.getSuffix(this)&quot;,
530         w: &quot;this.getDay()&quot;,
531         z: &quot;Ext.Date.getDayOfYear(this)&quot;,
532         W: &quot;Ext.String.leftPad(Ext.Date.getWeekOfYear(this), 2, '0')&quot;,
533         F: &quot;Ext.Date.monthNames[this.getMonth()]&quot;,
534         m: &quot;Ext.String.leftPad(this.getMonth() + 1, 2, '0')&quot;,
535         M: &quot;Ext.Date.getShortMonthName(this.getMonth())&quot;, // get localised short month name
536         n: &quot;(this.getMonth() + 1)&quot;,
537         t: &quot;Ext.Date.getDaysInMonth(this)&quot;,
538         L: &quot;(Ext.Date.isLeapYear(this) ? 1 : 0)&quot;,
539         o: &quot;(this.getFullYear() + (Ext.Date.getWeekOfYear(this) == 1 &amp;&amp; this.getMonth() &gt; 0 ? +1 : (Ext.Date.getWeekOfYear(this) &gt;= 52 &amp;&amp; this.getMonth() &lt; 11 ? -1 : 0)))&quot;,
540         Y: &quot;Ext.String.leftPad(this.getFullYear(), 4, '0')&quot;,
541         y: &quot;('' + this.getFullYear()).substring(2, 4)&quot;,
542         a: &quot;(this.getHours() &lt; 12 ? 'am' : 'pm')&quot;,
543         A: &quot;(this.getHours() &lt; 12 ? 'AM' : 'PM')&quot;,
544         g: &quot;((this.getHours() % 12) ? this.getHours() % 12 : 12)&quot;,
545         G: &quot;this.getHours()&quot;,
546         h: &quot;Ext.String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')&quot;,
547         H: &quot;Ext.String.leftPad(this.getHours(), 2, '0')&quot;,
548         i: &quot;Ext.String.leftPad(this.getMinutes(), 2, '0')&quot;,
549         s: &quot;Ext.String.leftPad(this.getSeconds(), 2, '0')&quot;,
550         u: &quot;Ext.String.leftPad(this.getMilliseconds(), 3, '0')&quot;,
551         O: &quot;Ext.Date.getGMTOffset(this)&quot;,
552         P: &quot;Ext.Date.getGMTOffset(this, true)&quot;,
553         T: &quot;Ext.Date.getTimezone(this)&quot;,
554         Z: &quot;(this.getTimezoneOffset() * -60)&quot;,
555
556         c: function() { // ISO-8601 -- GMT format
557             for (var c = &quot;Y-m-dTH:i:sP&quot;, code = [], i = 0, l = c.length; i &lt; l; ++i) {
558                 var e = c.charAt(i);
559                 code.push(e == &quot;T&quot; ? &quot;'T'&quot; : utilDate.getFormatCode(e)); // treat T as a character literal
560             }
561             return code.join(&quot; + &quot;);
562         },
563         /*
564         c: function() { // ISO-8601 -- UTC format
565             return [
566               &quot;this.getUTCFullYear()&quot;, &quot;'-'&quot;,
567               &quot;Ext.util.Format.leftPad(this.getUTCMonth() + 1, 2, '0')&quot;, &quot;'-'&quot;,
568               &quot;Ext.util.Format.leftPad(this.getUTCDate(), 2, '0')&quot;,
569               &quot;'T'&quot;,
570               &quot;Ext.util.Format.leftPad(this.getUTCHours(), 2, '0')&quot;, &quot;':'&quot;,
571               &quot;Ext.util.Format.leftPad(this.getUTCMinutes(), 2, '0')&quot;, &quot;':'&quot;,
572               &quot;Ext.util.Format.leftPad(this.getUTCSeconds(), 2, '0')&quot;,
573               &quot;'Z'&quot;
574             ].join(&quot; + &quot;);
575         },
576         */
577
578         U: &quot;Math.round(this.getTime() / 1000)&quot;
579     },
580
581 <span id='Ext-Date-method-isValid'>    /**
582 </span>     * Checks if the passed Date parameters will cause a javascript Date &quot;rollover&quot;.
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 &quot;rollover&quot;, false otherwise.
591      * @static
592      */
593     isValid : function(y, m, d, h, i, s, ms) {
594         // setup defaults
595         h = h || 0;
596         i = i || 0;
597         s = s || 0;
598         ms = ms || 0;
599
600         // Special handling for year &lt; 100
601         var dt = utilDate.add(new Date(y &lt; 100 ? 100 : y, m - 1, d, h, i, s, ms), utilDate.YEAR, y &lt; 100 ? y - 100 : 0);
602
603         return y == dt.getFullYear() &amp;&amp;
604             m == dt.getMonth() + 1 &amp;&amp;
605             d == dt.getDate() &amp;&amp;
606             h == dt.getHours() &amp;&amp;
607             i == dt.getMinutes() &amp;&amp;
608             s == dt.getSeconds() &amp;&amp;
609             ms == dt.getMilliseconds();
610     },
611
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      * &lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
621 //dt = Fri May 25 2007 (current date)
622 var dt = new Date();
623
624 //dt = Thu May 25 2006 (today&amp;#39;s month/day in 2006)
625 dt = Ext.Date.parse(&quot;2006&quot;, &quot;Y&quot;);
626
627 //dt = Sun Jan 15 2006 (all date parts specified)
628 dt = Ext.Date.parse(&quot;2006-01-15&quot;, &quot;Y-m-d&quot;);
629
630 //dt = Sun Jan 15 2006 15:20:01
631 dt = Ext.Date.parse(&quot;2006-01-15 3:20:01 PM&quot;, &quot;Y-m-d g:i:s A&quot;);
632
633 // attempt to parse Sun Feb 29 2006 03:20:01 in strict mode
634 dt = Ext.Date.parse(&quot;2006-02-29 03:20:01&quot;, &quot;Y-m-d H:i:s&quot;, true); // returns null
635 &lt;/code&gt;&lt;/pre&gt;
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 &quot;rollover&quot;)
639                         (defaults to false). Invalid date strings will return null when parsed.
640      * @return {Date} The parsed Date.
641      * @static
642      */
643     parse : function(input, format, strict) {
644         var p = utilDate.parseFunctions;
645         if (p[format] == null) {
646             utilDate.createParser(format);
647         }
648         return p[format](input, Ext.isDefined(strict) ? strict : utilDate.useStrict);
649     },
650
651     // Backwards compat
652     parseDate: function(input, format, strict){
653         return utilDate.parse(input, format, strict);
654     },
655
656
657     // private
658     getFormatCode : function(character) {
659         var f = utilDate.formatCodes[character];
660
661         if (f) {
662           f = typeof f == 'function'? f() : f;
663           utilDate.formatCodes[character] = f; // reassign function result to prevent repeated execution
664         }
665
666         // note: unknown characters are treated as literals
667         return f || (&quot;'&quot; + Ext.String.escape(character) + &quot;'&quot;);
668     },
669
670     // private
671     createFormat : function(format) {
672         var code = [],
673             special = false,
674             ch = '';
675
676         for (var i = 0; i &lt; format.length; ++i) {
677             ch = format.charAt(i);
678             if (!special &amp;&amp; ch == &quot;\\&quot;) {
679                 special = true;
680             } else if (special) {
681                 special = false;
682                 code.push(&quot;'&quot; + Ext.String.escape(ch) + &quot;'&quot;);
683             } else {
684                 code.push(utilDate.getFormatCode(ch));
685             }
686         }
687         utilDate.formatFunctions[format] = Ext.functionFactory(&quot;return &quot; + code.join('+'));
688     },
689
690     // private
691     createParser : (function() {
692         var code = [
693             &quot;var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,&quot;,
694                 &quot;def = Ext.Date.defaults,&quot;,
695                 &quot;results = String(input).match(Ext.Date.parseRegexes[{0}]);&quot;, // either null, or an array of matched strings
696
697             &quot;if(results){&quot;,
698                 &quot;{1}&quot;,
699
700                 &quot;if(u != null){&quot;, // i.e. unix time is defined
701                     &quot;v = new Date(u * 1000);&quot;, // give top priority to UNIX time
702                 &quot;}else{&quot;,
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                     &quot;dt = Ext.Date.clearTime(new Date);&quot;,
707
708                     // date calculations (note: these calculations create a dependency on Ext.Number.from())
709                     &quot;y = Ext.Number.from(y, Ext.Number.from(def.y, dt.getFullYear()));&quot;,
710                     &quot;m = Ext.Number.from(m, Ext.Number.from(def.m - 1, dt.getMonth()));&quot;,
711                     &quot;d = Ext.Number.from(d, Ext.Number.from(def.d, dt.getDate()));&quot;,
712
713                     // time calculations (note: these calculations create a dependency on Ext.Number.from())
714                     &quot;h  = Ext.Number.from(h, Ext.Number.from(def.h, dt.getHours()));&quot;,
715                     &quot;i  = Ext.Number.from(i, Ext.Number.from(def.i, dt.getMinutes()));&quot;,
716                     &quot;s  = Ext.Number.from(s, Ext.Number.from(def.s, dt.getSeconds()));&quot;,
717                     &quot;ms = Ext.Number.from(ms, Ext.Number.from(def.ms, dt.getMilliseconds()));&quot;,
718
719                     &quot;if(z &gt;= 0 &amp;&amp; y &gt;= 0){&quot;,
720                         // both the year and zero-based day of year are defined and &gt;= 0.
721                         // these 2 values alone provide sufficient info to create a full date object
722
723                         // create Date object representing January 1st for the given year
724                         // handle years &lt; 100 appropriately
725                         &quot;v = Ext.Date.add(new Date(y &lt; 100 ? 100 : y, 0, 1, h, i, s, ms), Ext.Date.YEAR, y &lt; 100 ? y - 100 : 0);&quot;,
726
727                         // then add day of year, checking for Date &quot;rollover&quot; if necessary
728                         &quot;v = !strict? v : (strict === true &amp;&amp; (z &lt;= 364 || (Ext.Date.isLeapYear(v) &amp;&amp; z &lt;= 365))? Ext.Date.add(v, Ext.Date.DAY, z) : null);&quot;,
729                     &quot;}else if(strict === true &amp;&amp; !Ext.Date.isValid(y, m + 1, d, h, i, s, ms)){&quot;, // check for Date &quot;rollover&quot;
730                         &quot;v = null;&quot;, // invalid date, so return null
731                     &quot;}else{&quot;,
732                         // plain old Date object
733                         // handle years &lt; 100 properly
734                         &quot;v = Ext.Date.add(new Date(y &lt; 100 ? 100 : y, m, d, h, i, s, ms), Ext.Date.YEAR, y &lt; 100 ? y - 100 : 0);&quot;,
735                     &quot;}&quot;,
736                 &quot;}&quot;,
737             &quot;}&quot;,
738
739             &quot;if(v){&quot;,
740                 // favour UTC offset over GMT offset
741                 &quot;if(zz != null){&quot;,
742                     // reset to UTC, then add offset
743                     &quot;v = Ext.Date.add(v, Ext.Date.SECOND, -v.getTimezoneOffset() * 60 - zz);&quot;,
744                 &quot;}else if(o){&quot;,
745                     // reset to GMT, then add offset
746                     &quot;v = Ext.Date.add(v, Ext.Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn));&quot;,
747                 &quot;}&quot;,
748             &quot;}&quot;,
749
750             &quot;return v;&quot;
751         ].join('\n');
752
753         return function(format) {
754             var regexNum = utilDate.parseRegexes.length,
755                 currentGroup = 1,
756                 calc = [],
757                 regex = [],
758                 special = false,
759                 ch = &quot;&quot;;
760
761             for (var i = 0; i &lt; format.length; ++i) {
762                 ch = format.charAt(i);
763                 if (!special &amp;&amp; ch == &quot;\\&quot;) {
764                     special = true;
765                 } else if (special) {
766                     special = false;
767                     regex.push(Ext.String.escape(ch));
768                 } else {
769                     var obj = utilDate.formatCodeToRegex(ch, currentGroup);
770                     currentGroup += obj.g;
771                     regex.push(obj.s);
772                     if (obj.g &amp;&amp; obj.c) {
773                         calc.push(obj.c);
774                     }
775                 }
776             }
777
778             utilDate.parseRegexes[regexNum] = new RegExp(&quot;^&quot; + regex.join('') + &quot;$&quot;, 'i');
779             utilDate.parseFunctions[format] = Ext.functionFactory(&quot;input&quot;, &quot;strict&quot;, xf(code, regexNum, calc.join('')));
780         };
781     })(),
782
783     // private
784     parseCodes : {
785         /*
786          * Notes:
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'
790          */
791         d: {
792             g:1,
793             c:&quot;d = parseInt(results[{0}], 10);\n&quot;,
794             s:&quot;(\\d{2})&quot; // day of month with leading zeroes (01 - 31)
795         },
796         j: {
797             g:1,
798             c:&quot;d = parseInt(results[{0}], 10);\n&quot;,
799             s:&quot;(\\d{1,2})&quot; // day of month without leading zeroes (1 - 31)
800         },
801         D: function() {
802             for (var a = [], i = 0; i &lt; 7; a.push(utilDate.getShortDayName(i)), ++i); // get localised short day names
803             return {
804                 g:0,
805                 c:null,
806                 s:&quot;(?:&quot; + a.join(&quot;|&quot;) +&quot;)&quot;
807             };
808         },
809         l: function() {
810             return {
811                 g:0,
812                 c:null,
813                 s:&quot;(?:&quot; + utilDate.dayNames.join(&quot;|&quot;) + &quot;)&quot;
814             };
815         },
816         N: {
817             g:0,
818             c:null,
819             s:&quot;[1-7]&quot; // ISO-8601 day number (1 (monday) - 7 (sunday))
820         },
821         S: {
822             g:0,
823             c:null,
824             s:&quot;(?:st|nd|rd|th)&quot;
825         },
826         w: {
827             g:0,
828             c:null,
829             s:&quot;[0-6]&quot; // javascript day number (0 (sunday) - 6 (saturday))
830         },
831         z: {
832             g:1,
833             c:&quot;z = parseInt(results[{0}], 10);\n&quot;,
834             s:&quot;(\\d{1,3})&quot; // day of the year (0 - 364 (365 in leap years))
835         },
836         W: {
837             g:0,
838             c:null,
839             s:&quot;(?:\\d{2})&quot; // ISO-8601 week number (with leading zero)
840         },
841         F: function() {
842             return {
843                 g:1,
844                 c:&quot;m = parseInt(Ext.Date.getMonthNumber(results[{0}]), 10);\n&quot;, // get localised month number
845                 s:&quot;(&quot; + utilDate.monthNames.join(&quot;|&quot;) + &quot;)&quot;
846             };
847         },
848         M: function() {
849             for (var a = [], i = 0; i &lt; 12; a.push(utilDate.getShortMonthName(i)), ++i); // get localised short month names
850             return Ext.applyIf({
851                 s:&quot;(&quot; + a.join(&quot;|&quot;) + &quot;)&quot;
852             }, utilDate.formatCodeToRegex(&quot;F&quot;));
853         },
854         m: {
855             g:1,
856             c:&quot;m = parseInt(results[{0}], 10) - 1;\n&quot;,
857             s:&quot;(\\d{2})&quot; // month number with leading zeros (01 - 12)
858         },
859         n: {
860             g:1,
861             c:&quot;m = parseInt(results[{0}], 10) - 1;\n&quot;,
862             s:&quot;(\\d{1,2})&quot; // month number without leading zeros (1 - 12)
863         },
864         t: {
865             g:0,
866             c:null,
867             s:&quot;(?:\\d{2})&quot; // no. of days in the month (28 - 31)
868         },
869         L: {
870             g:0,
871             c:null,
872             s:&quot;(?:1|0)&quot;
873         },
874         o: function() {
875             return utilDate.formatCodeToRegex(&quot;Y&quot;);
876         },
877         Y: {
878             g:1,
879             c:&quot;y = parseInt(results[{0}], 10);\n&quot;,
880             s:&quot;(\\d{4})&quot; // 4-digit year
881         },
882         y: {
883             g:1,
884             c:&quot;var ty = parseInt(results[{0}], 10);\n&quot;
885                 + &quot;y = ty &gt; Ext.Date.y2kYear ? 1900 + ty : 2000 + ty;\n&quot;, // 2-digit year
886             s:&quot;(\\d{1,2})&quot;
887         },
888         /*
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.
892          */
893         a: {
894             g:1,
895             c:&quot;if (/(am)/i.test(results[{0}])) {\n&quot;
896                 + &quot;if (!h || h == 12) { h = 0; }\n&quot;
897                 + &quot;} else { if (!h || h &lt; 12) { h = (h || 0) + 12; }}&quot;,
898             s:&quot;(am|pm|AM|PM)&quot;
899         },
900         A: {
901             g:1,
902             c:&quot;if (/(am)/i.test(results[{0}])) {\n&quot;
903                 + &quot;if (!h || h == 12) { h = 0; }\n&quot;
904                 + &quot;} else { if (!h || h &lt; 12) { h = (h || 0) + 12; }}&quot;,
905             s:&quot;(AM|PM|am|pm)&quot;
906         },
907         g: function() {
908             return utilDate.formatCodeToRegex(&quot;G&quot;);
909         },
910         G: {
911             g:1,
912             c:&quot;h = parseInt(results[{0}], 10);\n&quot;,
913             s:&quot;(\\d{1,2})&quot; // 24-hr format of an hour without leading zeroes (0 - 23)
914         },
915         h: function() {
916             return utilDate.formatCodeToRegex(&quot;H&quot;);
917         },
918         H: {
919             g:1,
920             c:&quot;h = parseInt(results[{0}], 10);\n&quot;,
921             s:&quot;(\\d{2})&quot; //  24-hr format of an hour with leading zeroes (00 - 23)
922         },
923         i: {
924             g:1,
925             c:&quot;i = parseInt(results[{0}], 10);\n&quot;,
926             s:&quot;(\\d{2})&quot; // minutes with leading zeros (00 - 59)
927         },
928         s: {
929             g:1,
930             c:&quot;s = parseInt(results[{0}], 10);\n&quot;,
931             s:&quot;(\\d{2})&quot; // seconds with leading zeros (00 - 59)
932         },
933         u: {
934             g:1,
935             c:&quot;ms = results[{0}]; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n&quot;,
936             s:&quot;(\\d+)&quot; // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
937         },
938         O: {
939             g:1,
940             c:[
941                 &quot;o = results[{0}];&quot;,
942                 &quot;var sn = o.substring(0,1),&quot;, // get + / - sign
943                     &quot;hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60),&quot;, // get hours (performs minutes-to-hour conversion also, just in case)
944                     &quot;mn = o.substring(3,5) % 60;&quot;, // get minutes
945                 &quot;o = ((-12 &lt;= (hr*60 + mn)/60) &amp;&amp; ((hr*60 + mn)/60 &lt;= 14))? (sn + Ext.String.leftPad(hr, 2, '0') + Ext.String.leftPad(mn, 2, '0')) : null;\n&quot; // -12hrs &lt;= GMT offset &lt;= 14hrs
946             ].join(&quot;\n&quot;),
947             s: &quot;([+\-]\\d{4})&quot; // GMT offset in hrs and mins
948         },
949         P: {
950             g:1,
951             c:[
952                 &quot;o = results[{0}];&quot;,
953                 &quot;var sn = o.substring(0,1),&quot;, // get + / - sign
954                     &quot;hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60),&quot;, // get hours (performs minutes-to-hour conversion also, just in case)
955                     &quot;mn = o.substring(4,6) % 60;&quot;, // get minutes
956                 &quot;o = ((-12 &lt;= (hr*60 + mn)/60) &amp;&amp; ((hr*60 + mn)/60 &lt;= 14))? (sn + Ext.String.leftPad(hr, 2, '0') + Ext.String.leftPad(mn, 2, '0')) : null;\n&quot; // -12hrs &lt;= GMT offset &lt;= 14hrs
957             ].join(&quot;\n&quot;),
958             s: &quot;([+\-]\\d{2}:\\d{2})&quot; // GMT offset in hrs and mins (with colon separator)
959         },
960         T: {
961             g:0,
962             c:null,
963             s:&quot;[A-Z]{1,4}&quot; // timezone abbrev. may be between 1 - 4 chars
964         },
965         Z: {
966             g:1,
967             c:&quot;zz = results[{0}] * 1;\n&quot; // -43200 &lt;= UTC offset &lt;= 50400
968                   + &quot;zz = (-43200 &lt;= zz &amp;&amp; zz &lt;= 50400)? zz : null;\n&quot;,
969             s:&quot;([+\-]?\\d{1,5})&quot; // leading '+' sign is optional for UTC offset
970         },
971         c: function() {
972             var calc = [],
973                 arr = [
974                     utilDate.formatCodeToRegex(&quot;Y&quot;, 1), // year
975                     utilDate.formatCodeToRegex(&quot;m&quot;, 2), // month
976                     utilDate.formatCodeToRegex(&quot;d&quot;, 3), // day
977                     utilDate.formatCodeToRegex(&quot;h&quot;, 4), // hour
978                     utilDate.formatCodeToRegex(&quot;i&quot;, 5), // minute
979                     utilDate.formatCodeToRegex(&quot;s&quot;, 6), // second
980                     {c:&quot;ms = results[7] || '0'; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n&quot;}, // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
981                     {c:[ // allow either &quot;Z&quot; (i.e. UTC) or &quot;-0530&quot; or &quot;+08:00&quot; (i.e. UTC offset) timezone delimiters. assumes local timezone if no timezone is specified
982                         &quot;if(results[8]) {&quot;, // timezone specified
983                             &quot;if(results[8] == 'Z'){&quot;,
984                                 &quot;zz = 0;&quot;, // UTC
985                             &quot;}else if (results[8].indexOf(':') &gt; -1){&quot;,
986                                 utilDate.formatCodeToRegex(&quot;P&quot;, 8).c, // timezone offset with colon separator
987                             &quot;}else{&quot;,
988                                 utilDate.formatCodeToRegex(&quot;O&quot;, 8).c, // timezone offset without colon separator
989                             &quot;}&quot;,
990                         &quot;}&quot;
991                     ].join('\n')}
992                 ];
993
994             for (var i = 0, l = arr.length; i &lt; l; ++i) {
995                 calc.push(arr[i].c);
996             }
997
998             return {
999                 g:1,
1000                 c:calc.join(&quot;&quot;),
1001                 s:[
1002                     arr[0].s, // year (required)
1003                     &quot;(?:&quot;, &quot;-&quot;, arr[1].s, // month (optional)
1004                         &quot;(?:&quot;, &quot;-&quot;, arr[2].s, // day (optional)
1005                             &quot;(?:&quot;,
1006                                 &quot;(?:T| )?&quot;, // time delimiter -- either a &quot;T&quot; or a single blank space
1007                                 arr[3].s, &quot;:&quot;, arr[4].s,  // hour AND minute, delimited by a single colon (optional). MUST be preceded by either a &quot;T&quot; or a single blank space
1008                                 &quot;(?::&quot;, arr[5].s, &quot;)?&quot;, // seconds (optional)
1009                                 &quot;(?:(?:\\.|,)(\\d+))?&quot;, // decimal fraction of a second (e.g. &quot;,12345&quot; or &quot;.98765&quot;) (optional)
1010                                 &quot;(Z|(?:[-+]\\d{2}(?::)?\\d{2}))?&quot;, // &quot;Z&quot; (UTC) or &quot;-0530&quot; (UTC offset without colon delimiter) or &quot;+08:00&quot; (UTC offset with colon delimiter) (optional)
1011                             &quot;)?&quot;,
1012                         &quot;)?&quot;,
1013                     &quot;)?&quot;
1014                 ].join(&quot;&quot;)
1015             };
1016         },
1017         U: {
1018             g:1,
1019             c:&quot;u = parseInt(results[{0}], 10);\n&quot;,
1020             s:&quot;(-?\\d+)&quot; // leading minus sign indicates seconds before UNIX epoch
1021         }
1022     },
1023
1024     //Old Ext.Date prototype methods.
1025     // private
1026     dateFormat: function(date, format) {
1027         return utilDate.format(date, format);
1028     },
1029
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
1035      */
1036     format: function(date, format) {
1037         if (utilDate.formatFunctions[format] == null) {
1038             utilDate.createFormat(format);
1039         }
1040         var result = utilDate.formatFunctions[format].call(date);
1041         return result + '';
1042     },
1043
1044 <span id='Ext-Date-method-getTimezone'>    /**
1045 </span>     * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
1046      *
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. &quot;Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)&quot;,
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' ...).
1055      */
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:
1058         //
1059         // Opera  : &quot;Thu, 25 Oct 2007 22:53:45 GMT+0800&quot; -- shortest (weirdest) date string of the lot
1060         // Safari : &quot;Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)&quot; -- value in parentheses always gives the correct timezone (same as FF)
1061         // FF     : &quot;Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)&quot; -- value in parentheses always gives the correct timezone
1062         // IE     : &quot;Thu Oct 25 22:54:35 UTC+0800 2007&quot; -- (Asian system setting) look for 3-4 letter timezone abbrev
1063         // IE     : &quot;Thu Oct 25 17:06:37 PDT 2007&quot; -- (American system setting) look for 3-4 letter timezone abbrev
1064         //
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+)?)$/, &quot;$1$2&quot;).replace(/[^A-Z]/g, &quot;&quot;);
1070     },
1071
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').
1077      */
1078     getGMTOffset : function(date, colon) {
1079         var offset = date.getTimezoneOffset();
1080         return (offset &gt; 0 ? &quot;-&quot; : &quot;+&quot;)
1081             + Ext.String.leftPad(Math.floor(Math.abs(offset) / 60), 2, &quot;0&quot;)
1082             + (colon ? &quot;:&quot; : &quot;&quot;)
1083             + Ext.String.leftPad(Math.abs(offset % 60), 2, &quot;0&quot;);
1084     },
1085
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).
1090      */
1091     getDayOfYear: function(date) {
1092         var num = 0,
1093             d = Ext.Date.clone(date),
1094             m = date.getMonth(),
1095             i;
1096
1097         for (i = 0, d.setDate(1), d.setMonth(0); i &lt; m; d.setMonth(++i)) {
1098             num += utilDate.getDaysInMonth(d);
1099         }
1100         return num + date.getDate() - 1;
1101     },
1102
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
1108      * @method
1109      */
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
1114
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();
1119
1120             return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
1121         };
1122     })(),
1123
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.
1128      */
1129     isLeapYear : function(date) {
1130         var year = date.getFullYear();
1131         return !!((year &amp; 3) == 0 &amp;&amp; (year % 100 || (year % 400 == 0 &amp;&amp; year)));
1132     },
1133
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.
1138      * Example:
1139      * &lt;pre&gt;&lt;code&gt;
1140 var dt = new Date('1/10/2007'),
1141     firstDay = Ext.Date.getFirstDayOfMonth(dt);
1142 console.log(Ext.Date.dayNames[firstDay]); //output: 'Monday'
1143      * &lt;/code&gt;&lt;/pre&gt;
1144      * @param {Date} date The date
1145      * @return {Number} The day number (0-6).
1146      */
1147     getFirstDayOfMonth : function(date) {
1148         var day = (date.getDay() - (date.getDate() - 1)) % 7;
1149         return (day &lt; 0) ? (day + 7) : day;
1150     },
1151
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.
1156      * Example:
1157      * &lt;pre&gt;&lt;code&gt;
1158 var dt = new Date('1/10/2007'),
1159     lastDay = Ext.Date.getLastDayOfMonth(dt);
1160 console.log(Ext.Date.dayNames[lastDay]); //output: 'Wednesday'
1161      * &lt;/code&gt;&lt;/pre&gt;
1162      * @param {Date} date The date
1163      * @return {Number} The day number (0-6).
1164      */
1165     getLastDayOfMonth : function(date) {
1166         return utilDate.getLastDateOfMonth(date).getDay();
1167     },
1168
1169
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
1173      * @return {Date}
1174      */
1175     getFirstDateOfMonth : function(date) {
1176         return new Date(date.getFullYear(), date.getMonth(), 1);
1177     },
1178
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
1182      * @return {Date}
1183      */
1184     getLastDateOfMonth : function(date) {
1185         return new Date(date.getFullYear(), date.getMonth(), utilDate.getDaysInMonth(date));
1186     },
1187
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.
1192      * @method
1193      */
1194     getDaysInMonth: (function() {
1195         var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
1196
1197         return function(date) { // return a closure for efficiency
1198             var m = date.getMonth();
1199
1200             return m == 1 &amp;&amp; utilDate.isLeapYear(date) ? 29 : daysInMonth[m];
1201         };
1202     })(),
1203
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'.
1208      */
1209     getSuffix : function(date) {
1210         switch (date.getDate()) {
1211             case 1:
1212             case 21:
1213             case 31:
1214                 return &quot;st&quot;;
1215             case 2:
1216             case 22:
1217                 return &quot;nd&quot;;
1218             case 3:
1219             case 23:
1220                 return &quot;rd&quot;;
1221             default:
1222                 return &quot;th&quot;;
1223         }
1224     },
1225
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.
1231      *
1232      * Example of correctly cloning a date:
1233      * &lt;pre&gt;&lt;code&gt;
1234 //wrong way:
1235 var orig = new Date('10/1/2006');
1236 var copy = orig;
1237 copy.setDate(5);
1238 console.log(orig);  //returns 'Thu Oct 05 2006'!
1239
1240 //correct way:
1241 var orig = new Date('10/1/2006'),
1242     copy = Ext.Date.clone(orig);
1243 copy.setDate(5);
1244 console.log(orig);  //returns 'Thu Oct 01 2006'
1245      * &lt;/code&gt;&lt;/pre&gt;
1246      * @param {Date} date The date
1247      * @return {Date} The new Date instance.
1248      */
1249     clone : function(date) {
1250         return new Date(date.getTime());
1251     },
1252
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.
1257      */
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();
1262     },
1263
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.
1271      */
1272     clearTime : function(date, clone) {
1273         if (clone) {
1274             return Ext.Date.clearTime(Ext.Date.clone(date));
1275         }
1276
1277         // get current date before clearing time
1278         var d = date.getDate();
1279
1280         // clear time
1281         date.setHours(0);
1282         date.setMinutes(0);
1283         date.setSeconds(0);
1284         date.setMilliseconds(0);
1285
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
1289
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));
1292
1293             date.setDate(d);
1294             date.setHours(c.getHours());
1295         }
1296
1297         return date;
1298     },
1299
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.
1304      *
1305      * Examples:
1306      * &lt;pre&gt;&lt;code&gt;
1307 // Basic usage:
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'
1310
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'
1314
1315      * &lt;/code&gt;&lt;/pre&gt;
1316      *
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.
1321      */
1322     add : function(date, interval, value) {
1323         var d = Ext.Date.clone(date),
1324             Date = Ext.Date;
1325         if (!interval || value === 0) return d;
1326
1327         switch(interval.toLowerCase()) {
1328             case Ext.Date.MILLI:
1329                 d.setMilliseconds(d.getMilliseconds() + value);
1330                 break;
1331             case Ext.Date.SECOND:
1332                 d.setSeconds(d.getSeconds() + value);
1333                 break;
1334             case Ext.Date.MINUTE:
1335                 d.setMinutes(d.getMinutes() + value);
1336                 break;
1337             case Ext.Date.HOUR:
1338                 d.setHours(d.getHours() + value);
1339                 break;
1340             case Ext.Date.DAY:
1341                 d.setDate(d.getDate() + value);
1342                 break;
1343             case Ext.Date.MONTH:
1344                 var day = date.getDate();
1345                 if (day &gt; 28) {
1346                     day = Math.min(day, Ext.Date.getLastDateOfMonth(Ext.Date.add(Ext.Date.getFirstDateOfMonth(date), 'mo', value)).getDate());
1347                 }
1348                 d.setDate(day);
1349                 d.setMonth(date.getMonth() + value);
1350                 break;
1351             case Ext.Date.YEAR:
1352                 d.setFullYear(date.getFullYear() + value);
1353                 break;
1354         }
1355         return d;
1356     },
1357
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.
1364      */
1365     between : function(date, start, end) {
1366         var t = date.getTime();
1367         return start.getTime() &lt;= t &amp;&amp; t &lt;= end.getTime();
1368     },
1369
1370     //Maintains compatibility with old static and prototype window.Date methods.
1371     compat: function() {
1372         var nativeDate = window.Date,
1373             p, u,
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'];
1376
1377         //Append statics
1378         Ext.Array.forEach(statics, function(s) {
1379             nativeDate[s] = utilDate[s];
1380         });
1381
1382         //Append to prototype
1383         Ext.Array.forEach(proto, function(s) {
1384             nativeDate.prototype[s] = function() {
1385                 var args = Array.prototype.slice.call(arguments);
1386                 args.unshift(this);
1387                 return utilDate[s].apply(utilDate, args);
1388             };
1389         });
1390     }
1391 };
1392
1393 var utilDate = Ext.Date;
1394
1395 })();
1396 </pre>
1397 </body>
1398 </html>