Date2.html 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483
  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="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  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. var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
  91. console.log(Ext.Date.format(dt, 'Y-m-d')); // 2007-01-10
  92. console.log(Ext.Date.format(dt, 'F j, Y, g:i a')); // January 10, 2007, 3:05 pm
  93. 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
  94. &lt;/code&gt;&lt;/pre&gt;
  95. *
  96. * Here are some standard date/time patterns that you might find helpful. They
  97. * are not part of the source of Ext.Date, but to use them you can simply copy this
  98. * block of code into any script that is included after Ext.Date and they will also become
  99. * globally available on the Date object. Feel free to add or remove patterns as needed in your code.
  100. * &lt;pre&gt;&lt;code&gt;
  101. Ext.Date.patterns = {
  102. ISO8601Long:&quot;Y-m-d H:i:s&quot;,
  103. ISO8601Short:&quot;Y-m-d&quot;,
  104. ShortDate: &quot;n/j/Y&quot;,
  105. LongDate: &quot;l, F d, Y&quot;,
  106. FullDateTime: &quot;l, F d, Y g:i:s A&quot;,
  107. MonthDay: &quot;F d&quot;,
  108. ShortTime: &quot;g:i A&quot;,
  109. LongTime: &quot;g:i:s A&quot;,
  110. SortableDateTime: &quot;Y-m-d\\TH:i:s&quot;,
  111. UniversalSortableDateTime: &quot;Y-m-d H:i:sO&quot;,
  112. YearMonth: &quot;F, Y&quot;
  113. };
  114. &lt;/code&gt;&lt;/pre&gt;
  115. *
  116. * Example usage:
  117. * &lt;pre&gt;&lt;code&gt;
  118. var dt = new Date();
  119. console.log(Ext.Date.format(dt, Ext.Date.patterns.ShortDate));
  120. &lt;/code&gt;&lt;/pre&gt;
  121. * &lt;p&gt;Developer-written, custom formats may be used by supplying both a formatting and a parsing function
  122. * which perform to specialized requirements. The functions are stored in {@link #parseFunctions} and {@link #formatFunctions}.&lt;/p&gt;
  123. * @singleton
  124. */
  125. /*
  126. * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
  127. * (see http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/)
  128. * They generate precompiled functions from format patterns instead of parsing and
  129. * processing each pattern every time a date is formatted. These functions are available
  130. * on every Date object.
  131. */
  132. (function() {
  133. // create private copy of Ext's Ext.util.Format.format() method
  134. // - to remove unnecessary dependency
  135. // - to resolve namespace conflict with MS-Ajax's implementation
  136. function xf(format) {
  137. var args = Array.prototype.slice.call(arguments, 1);
  138. return format.replace(/\{(\d+)\}/g, function(m, i) {
  139. return args[i];
  140. });
  141. }
  142. Ext.Date = {
  143. <span id='Ext-Date-method-now'> /**
  144. </span> * Returns the current timestamp.
  145. * @return {Number} Milliseconds since UNIX epoch.
  146. * @method
  147. */
  148. now: Date.now || function() {
  149. return +new Date();
  150. },
  151. <span id='Ext-Date-method-toString'> /**
  152. </span> * @private
  153. * Private for now
  154. */
  155. toString: function(date) {
  156. var pad = Ext.String.leftPad;
  157. return date.getFullYear() + &quot;-&quot;
  158. + pad(date.getMonth() + 1, 2, '0') + &quot;-&quot;
  159. + pad(date.getDate(), 2, '0') + &quot;T&quot;
  160. + pad(date.getHours(), 2, '0') + &quot;:&quot;
  161. + pad(date.getMinutes(), 2, '0') + &quot;:&quot;
  162. + pad(date.getSeconds(), 2, '0');
  163. },
  164. <span id='Ext-Date-method-getElapsed'> /**
  165. </span> * Returns the number of milliseconds between two dates
  166. * @param {Date} dateA The first date
  167. * @param {Date} dateB (optional) The second date, defaults to now
  168. * @return {Number} The difference in milliseconds
  169. */
  170. getElapsed: function(dateA, dateB) {
  171. return Math.abs(dateA - (dateB || new Date()));
  172. },
  173. <span id='Ext-Date-property-useStrict'> /**
  174. </span> * Global flag which determines if strict date parsing should be used.
  175. * Strict date parsing will not roll-over invalid dates, which is the
  176. * default behaviour of javascript Date objects.
  177. * (see {@link #parse} for more information)
  178. * Defaults to &lt;tt&gt;false&lt;/tt&gt;.
  179. * @type Boolean
  180. */
  181. useStrict: false,
  182. // private
  183. formatCodeToRegex: function(character, currentGroup) {
  184. // Note: currentGroup - position in regex result array (see notes for Ext.Date.parseCodes below)
  185. var p = utilDate.parseCodes[character];
  186. if (p) {
  187. p = typeof p == 'function'? p() : p;
  188. utilDate.parseCodes[character] = p; // reassign function result to prevent repeated execution
  189. }
  190. return p ? Ext.applyIf({
  191. c: p.c ? xf(p.c, currentGroup || &quot;{0}&quot;) : p.c
  192. }, p) : {
  193. g: 0,
  194. c: null,
  195. s: Ext.String.escapeRegex(character) // treat unrecognised characters as literals
  196. };
  197. },
  198. <span id='Ext-Date-property-parseFunctions'> /**
  199. </span> * &lt;p&gt;An object hash in which each property is a date parsing function. The property name is the
  200. * format string which that function parses.&lt;/p&gt;
  201. * &lt;p&gt;This object is automatically populated with date parsing functions as
  202. * date formats are requested for Ext standard formatting strings.&lt;/p&gt;
  203. * &lt;p&gt;Custom parsing functions may be inserted into this object, keyed by a name which from then on
  204. * may be used as a format string to {@link #parse}.&lt;p&gt;
  205. * &lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  206. Ext.Date.parseFunctions['x-date-format'] = myDateParser;
  207. &lt;/code&gt;&lt;/pre&gt;
  208. * &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;
  209. * &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;
  210. * &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
  211. * (i.e. prevent javascript Date &quot;rollover&quot;) (The default must be false).
  212. * Invalid date strings should return null when parsed.&lt;/div&gt;&lt;/li&gt;
  213. * &lt;/ul&gt;&lt;/div&gt;&lt;/p&gt;
  214. * &lt;p&gt;To enable Dates to also be &lt;i&gt;formatted&lt;/i&gt; according to that format, a corresponding
  215. * formatting function must be placed into the {@link #formatFunctions} property.
  216. * @property parseFunctions
  217. * @type Object
  218. */
  219. parseFunctions: {
  220. &quot;MS&quot;: function(input, strict) {
  221. // note: the timezone offset is ignored since the MS Ajax server sends
  222. // a UTC milliseconds-since-Unix-epoch value (negative values are allowed)
  223. var re = new RegExp('\\/Date\\(([-+])?(\\d+)(?:[+-]\\d{4})?\\)\\/'),
  224. r = (input || '').match(re);
  225. return r? new Date(((r[1] || '') + r[2]) * 1) : null;
  226. }
  227. },
  228. parseRegexes: [],
  229. <span id='Ext-Date-property-formatFunctions'> /**
  230. </span> * &lt;p&gt;An object hash in which each property is a date formatting function. The property name is the
  231. * format string which corresponds to the produced formatted date string.&lt;/p&gt;
  232. * &lt;p&gt;This object is automatically populated with date formatting functions as
  233. * date formats are requested for Ext standard formatting strings.&lt;/p&gt;
  234. * &lt;p&gt;Custom formatting functions may be inserted into this object, keyed by a name which from then on
  235. * may be used as a format string to {@link #format}. Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  236. Ext.Date.formatFunctions['x-date-format'] = myDateFormatter;
  237. &lt;/code&gt;&lt;/pre&gt;
  238. * &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;
  239. * &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;
  240. * &lt;/ul&gt;&lt;/div&gt;&lt;/p&gt;
  241. * &lt;p&gt;To enable date strings to also be &lt;i&gt;parsed&lt;/i&gt; according to that format, a corresponding
  242. * parsing function must be placed into the {@link #parseFunctions} property.
  243. * @property formatFunctions
  244. * @type Object
  245. */
  246. formatFunctions: {
  247. &quot;MS&quot;: function() {
  248. // UTC milliseconds since Unix epoch (MS-AJAX serialized date format (MRSF))
  249. return '\\/Date(' + this.getTime() + ')\\/';
  250. }
  251. },
  252. y2kYear : 50,
  253. <span id='Ext-Date-property-MILLI'> /**
  254. </span> * Date interval constant
  255. * @type String
  256. */
  257. MILLI : &quot;ms&quot;,
  258. <span id='Ext-Date-property-SECOND'> /**
  259. </span> * Date interval constant
  260. * @type String
  261. */
  262. SECOND : &quot;s&quot;,
  263. <span id='Ext-Date-property-MINUTE'> /**
  264. </span> * Date interval constant
  265. * @type String
  266. */
  267. MINUTE : &quot;mi&quot;,
  268. <span id='Ext-Date-property-HOUR'> /** Date interval constant
  269. </span> * @type String
  270. */
  271. HOUR : &quot;h&quot;,
  272. <span id='Ext-Date-property-DAY'> /**
  273. </span> * Date interval constant
  274. * @type String
  275. */
  276. DAY : &quot;d&quot;,
  277. <span id='Ext-Date-property-MONTH'> /**
  278. </span> * Date interval constant
  279. * @type String
  280. */
  281. MONTH : &quot;mo&quot;,
  282. <span id='Ext-Date-property-YEAR'> /**
  283. </span> * Date interval constant
  284. * @type String
  285. */
  286. YEAR : &quot;y&quot;,
  287. <span id='Ext-Date-property-defaults'> /**
  288. </span> * &lt;p&gt;An object hash containing default date values used during date parsing.&lt;/p&gt;
  289. * &lt;p&gt;The following properties are available:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  290. * &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;
  291. * &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;
  292. * &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;
  293. * &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;
  294. * &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;
  295. * &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;
  296. * &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;
  297. * &lt;/ul&gt;&lt;/div&gt;&lt;/p&gt;
  298. * &lt;p&gt;Override these properties to customize the default date values used by the {@link #parse} method.&lt;/p&gt;
  299. * &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;
  300. * and &lt;tt&gt;ms&lt;/tt&gt; properties may coincide with the exact time in which DST takes effect.
  301. * It is the responsiblity of the developer to account for this.&lt;/b&gt;&lt;/p&gt;
  302. * Example Usage:
  303. * &lt;pre&gt;&lt;code&gt;
  304. // set default day value to the first day of the month
  305. Ext.Date.defaults.d = 1;
  306. // parse a February date string containing only year and month values.
  307. // setting the default day value to 1 prevents weird date rollover issues
  308. // when attempting to parse the following date string on, for example, March 31st 2009.
  309. Ext.Date.parse('2009-02', 'Y-m'); // returns a Date object representing February 1st 2009
  310. &lt;/code&gt;&lt;/pre&gt;
  311. * @property defaults
  312. * @type Object
  313. */
  314. defaults: {},
  315. //&lt;locale type=&quot;array&quot;&gt;
  316. <span id='Ext-Date-property-dayNames'> /**
  317. </span> * @property {String[]} dayNames
  318. * An array of textual day names.
  319. * Override these values for international dates.
  320. * Example:
  321. * &lt;pre&gt;&lt;code&gt;
  322. Ext.Date.dayNames = [
  323. 'SundayInYourLang',
  324. 'MondayInYourLang',
  325. ...
  326. ];
  327. &lt;/code&gt;&lt;/pre&gt;
  328. */
  329. dayNames : [
  330. &quot;Sunday&quot;,
  331. &quot;Monday&quot;,
  332. &quot;Tuesday&quot;,
  333. &quot;Wednesday&quot;,
  334. &quot;Thursday&quot;,
  335. &quot;Friday&quot;,
  336. &quot;Saturday&quot;
  337. ],
  338. //&lt;/locale&gt;
  339. //&lt;locale type=&quot;array&quot;&gt;
  340. <span id='Ext-Date-property-monthNames'> /**
  341. </span> * @property {String[]} monthNames
  342. * An array of textual month names.
  343. * Override these values for international dates.
  344. * Example:
  345. * &lt;pre&gt;&lt;code&gt;
  346. Ext.Date.monthNames = [
  347. 'JanInYourLang',
  348. 'FebInYourLang',
  349. ...
  350. ];
  351. &lt;/code&gt;&lt;/pre&gt;
  352. */
  353. monthNames : [
  354. &quot;January&quot;,
  355. &quot;February&quot;,
  356. &quot;March&quot;,
  357. &quot;April&quot;,
  358. &quot;May&quot;,
  359. &quot;June&quot;,
  360. &quot;July&quot;,
  361. &quot;August&quot;,
  362. &quot;September&quot;,
  363. &quot;October&quot;,
  364. &quot;November&quot;,
  365. &quot;December&quot;
  366. ],
  367. //&lt;/locale&gt;
  368. //&lt;locale type=&quot;object&quot;&gt;
  369. <span id='Ext-Date-property-monthNumbers'> /**
  370. </span> * @property {Object} monthNumbers
  371. * An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are case-sensitive).
  372. * Override these values for international dates.
  373. * Example:
  374. * &lt;pre&gt;&lt;code&gt;
  375. Ext.Date.monthNumbers = {
  376. 'LongJanNameInYourLang': 0,
  377. 'ShortJanNameInYourLang':0,
  378. 'LongFebNameInYourLang':1,
  379. 'ShortFebNameInYourLang':1,
  380. ...
  381. };
  382. &lt;/code&gt;&lt;/pre&gt;
  383. */
  384. monthNumbers : {
  385. January: 0,
  386. Jan: 0,
  387. February: 1,
  388. Feb: 1,
  389. March: 2,
  390. Mar: 2,
  391. April: 3,
  392. Apr: 3,
  393. May: 4,
  394. June: 5,
  395. Jun: 5,
  396. July: 6,
  397. Jul: 6,
  398. August: 7,
  399. Aug: 7,
  400. September: 8,
  401. Sep: 8,
  402. October: 9,
  403. Oct: 9,
  404. November: 10,
  405. Nov: 10,
  406. December: 11,
  407. Dec: 11
  408. },
  409. //&lt;/locale&gt;
  410. //&lt;locale&gt;
  411. <span id='Ext-Date-property-defaultFormat'> /**
  412. </span> * @property {String} defaultFormat
  413. * &lt;p&gt;The date format string that the {@link Ext.util.Format#dateRenderer}
  414. * and {@link Ext.util.Format#date} functions use. See {@link Ext.Date} for details.&lt;/p&gt;
  415. * &lt;p&gt;This may be overridden in a locale file.&lt;/p&gt;
  416. */
  417. defaultFormat : &quot;m/d/Y&quot;,
  418. //&lt;/locale&gt;
  419. //&lt;locale type=&quot;function&quot;&gt;
  420. <span id='Ext-Date-method-getShortMonthName'> /**
  421. </span> * Get the short month name for the given month number.
  422. * Override this function for international dates.
  423. * @param {Number} month A zero-based javascript month number.
  424. * @return {String} The short month name.
  425. */
  426. getShortMonthName : function(month) {
  427. return Ext.Date.monthNames[month].substring(0, 3);
  428. },
  429. //&lt;/locale&gt;
  430. //&lt;locale type=&quot;function&quot;&gt;
  431. <span id='Ext-Date-method-getShortDayName'> /**
  432. </span> * Get the short day name for the given day number.
  433. * Override this function for international dates.
  434. * @param {Number} day A zero-based javascript day number.
  435. * @return {String} The short day name.
  436. */
  437. getShortDayName : function(day) {
  438. return Ext.Date.dayNames[day].substring(0, 3);
  439. },
  440. //&lt;/locale&gt;
  441. //&lt;locale type=&quot;function&quot;&gt;
  442. <span id='Ext-Date-method-getMonthNumber'> /**
  443. </span> * Get the zero-based javascript month number for the given short/full month name.
  444. * Override this function for international dates.
  445. * @param {String} name The short/full month name.
  446. * @return {Number} The zero-based javascript month number.
  447. */
  448. getMonthNumber : function(name) {
  449. // handle camel casing for english month names (since the keys for the Ext.Date.monthNumbers hash are case sensitive)
  450. return Ext.Date.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()];
  451. },
  452. //&lt;/locale&gt;
  453. <span id='Ext-Date-method-formatContainsHourInfo'> /**
  454. </span> * Checks if the specified format contains hour information
  455. * @param {String} format The format to check
  456. * @return {Boolean} True if the format contains hour information
  457. * @method
  458. */
  459. formatContainsHourInfo : (function(){
  460. var stripEscapeRe = /(\\.)/g,
  461. hourInfoRe = /([gGhHisucUOPZ]|MS)/;
  462. return function(format){
  463. return hourInfoRe.test(format.replace(stripEscapeRe, ''));
  464. };
  465. }()),
  466. <span id='Ext-Date-method-formatContainsDateInfo'> /**
  467. </span> * Checks if the specified format contains information about
  468. * anything other than the time.
  469. * @param {String} format The format to check
  470. * @return {Boolean} True if the format contains information about
  471. * date/day information.
  472. * @method
  473. */
  474. formatContainsDateInfo : (function(){
  475. var stripEscapeRe = /(\\.)/g,
  476. dateInfoRe = /([djzmnYycU]|MS)/;
  477. return function(format){
  478. return dateInfoRe.test(format.replace(stripEscapeRe, ''));
  479. };
  480. }()),
  481. <span id='Ext-Date-method-unescapeFormat'> /**
  482. </span> * Removes all escaping for a date format string. In date formats,
  483. * using a '\' can be used to escape special characters.
  484. * @param {String} format The format to unescape
  485. * @return {String} The unescaped format
  486. * @method
  487. */
  488. unescapeFormat: (function() {
  489. var slashRe = /\\/gi;
  490. return function(format) {
  491. // Escape the format, since \ can be used to escape special
  492. // characters in a date format. For example, in a spanish
  493. // locale the format may be: 'd \\de F \\de Y'
  494. return format.replace(slashRe, '');
  495. }
  496. }()),
  497. <span id='Ext-Date-property-formatCodes'> /**
  498. </span> * The base format-code to formatting-function hashmap used by the {@link #format} method.
  499. * Formatting functions are strings (or functions which return strings) which
  500. * will return the appropriate value when evaluated in the context of the Date object
  501. * from which the {@link #format} method is called.
  502. * Add to / override these mappings for custom date formatting.
  503. * Note: Ext.Date.format() treats characters as literals if an appropriate mapping cannot be found.
  504. * Example:
  505. * &lt;pre&gt;&lt;code&gt;
  506. Ext.Date.formatCodes.x = &quot;Ext.util.Format.leftPad(this.getDate(), 2, '0')&quot;;
  507. console.log(Ext.Date.format(new Date(), 'X'); // returns the current day of the month
  508. &lt;/code&gt;&lt;/pre&gt;
  509. * @type Object
  510. */
  511. formatCodes : {
  512. d: &quot;Ext.String.leftPad(this.getDate(), 2, '0')&quot;,
  513. D: &quot;Ext.Date.getShortDayName(this.getDay())&quot;, // get localised short day name
  514. j: &quot;this.getDate()&quot;,
  515. l: &quot;Ext.Date.dayNames[this.getDay()]&quot;,
  516. N: &quot;(this.getDay() ? this.getDay() : 7)&quot;,
  517. S: &quot;Ext.Date.getSuffix(this)&quot;,
  518. w: &quot;this.getDay()&quot;,
  519. z: &quot;Ext.Date.getDayOfYear(this)&quot;,
  520. W: &quot;Ext.String.leftPad(Ext.Date.getWeekOfYear(this), 2, '0')&quot;,
  521. F: &quot;Ext.Date.monthNames[this.getMonth()]&quot;,
  522. m: &quot;Ext.String.leftPad(this.getMonth() + 1, 2, '0')&quot;,
  523. M: &quot;Ext.Date.getShortMonthName(this.getMonth())&quot;, // get localised short month name
  524. n: &quot;(this.getMonth() + 1)&quot;,
  525. t: &quot;Ext.Date.getDaysInMonth(this)&quot;,
  526. L: &quot;(Ext.Date.isLeapYear(this) ? 1 : 0)&quot;,
  527. 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;,
  528. Y: &quot;Ext.String.leftPad(this.getFullYear(), 4, '0')&quot;,
  529. y: &quot;('' + this.getFullYear()).substring(2, 4)&quot;,
  530. a: &quot;(this.getHours() &lt; 12 ? 'am' : 'pm')&quot;,
  531. A: &quot;(this.getHours() &lt; 12 ? 'AM' : 'PM')&quot;,
  532. g: &quot;((this.getHours() % 12) ? this.getHours() % 12 : 12)&quot;,
  533. G: &quot;this.getHours()&quot;,
  534. h: &quot;Ext.String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')&quot;,
  535. H: &quot;Ext.String.leftPad(this.getHours(), 2, '0')&quot;,
  536. i: &quot;Ext.String.leftPad(this.getMinutes(), 2, '0')&quot;,
  537. s: &quot;Ext.String.leftPad(this.getSeconds(), 2, '0')&quot;,
  538. u: &quot;Ext.String.leftPad(this.getMilliseconds(), 3, '0')&quot;,
  539. O: &quot;Ext.Date.getGMTOffset(this)&quot;,
  540. P: &quot;Ext.Date.getGMTOffset(this, true)&quot;,
  541. T: &quot;Ext.Date.getTimezone(this)&quot;,
  542. Z: &quot;(this.getTimezoneOffset() * -60)&quot;,
  543. c: function() { // ISO-8601 -- GMT format
  544. var c, code, i, l, e;
  545. for (c = &quot;Y-m-dTH:i:sP&quot;, code = [], i = 0, l = c.length; i &lt; l; ++i) {
  546. e = c.charAt(i);
  547. code.push(e == &quot;T&quot; ? &quot;'T'&quot; : utilDate.getFormatCode(e)); // treat T as a character literal
  548. }
  549. return code.join(&quot; + &quot;);
  550. },
  551. /*
  552. c: function() { // ISO-8601 -- UTC format
  553. return [
  554. &quot;this.getUTCFullYear()&quot;, &quot;'-'&quot;,
  555. &quot;Ext.util.Format.leftPad(this.getUTCMonth() + 1, 2, '0')&quot;, &quot;'-'&quot;,
  556. &quot;Ext.util.Format.leftPad(this.getUTCDate(), 2, '0')&quot;,
  557. &quot;'T'&quot;,
  558. &quot;Ext.util.Format.leftPad(this.getUTCHours(), 2, '0')&quot;, &quot;':'&quot;,
  559. &quot;Ext.util.Format.leftPad(this.getUTCMinutes(), 2, '0')&quot;, &quot;':'&quot;,
  560. &quot;Ext.util.Format.leftPad(this.getUTCSeconds(), 2, '0')&quot;,
  561. &quot;'Z'&quot;
  562. ].join(&quot; + &quot;);
  563. },
  564. */
  565. U: &quot;Math.round(this.getTime() / 1000)&quot;
  566. },
  567. <span id='Ext-Date-method-isValid'> /**
  568. </span> * Checks if the passed Date parameters will cause a javascript Date &quot;rollover&quot;.
  569. * @param {Number} year 4-digit year
  570. * @param {Number} month 1-based month-of-year
  571. * @param {Number} day Day of month
  572. * @param {Number} hour (optional) Hour
  573. * @param {Number} minute (optional) Minute
  574. * @param {Number} second (optional) Second
  575. * @param {Number} millisecond (optional) Millisecond
  576. * @return {Boolean} true if the passed parameters do not cause a Date &quot;rollover&quot;, false otherwise.
  577. */
  578. isValid : function(y, m, d, h, i, s, ms) {
  579. // setup defaults
  580. h = h || 0;
  581. i = i || 0;
  582. s = s || 0;
  583. ms = ms || 0;
  584. // Special handling for year &lt; 100
  585. 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);
  586. return y == dt.getFullYear() &amp;&amp;
  587. m == dt.getMonth() + 1 &amp;&amp;
  588. d == dt.getDate() &amp;&amp;
  589. h == dt.getHours() &amp;&amp;
  590. i == dt.getMinutes() &amp;&amp;
  591. s == dt.getSeconds() &amp;&amp;
  592. ms == dt.getMilliseconds();
  593. },
  594. <span id='Ext-Date-method-parse'> /**
  595. </span> * Parses the passed string using the specified date format.
  596. * Note that this function expects normal calendar dates, meaning that months are 1-based (i.e. 1 = January).
  597. * The {@link #defaults} hash will be used for any date value (i.e. year, month, day, hour, minute, second or millisecond)
  598. * which cannot be found in the passed string. If a corresponding default date value has not been specified in the {@link #defaults} hash,
  599. * the current date's year, month, day or DST-adjusted zero-hour time value will be used instead.
  600. * Keep in mind that the input date string must precisely match the specified format string
  601. * in order for the parse operation to be successful (failed parse operations return a null value).
  602. * &lt;p&gt;Example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  603. //dt = Fri May 25 2007 (current date)
  604. var dt = new Date();
  605. //dt = Thu May 25 2006 (today&amp;#39;s month/day in 2006)
  606. dt = Ext.Date.parse(&quot;2006&quot;, &quot;Y&quot;);
  607. //dt = Sun Jan 15 2006 (all date parts specified)
  608. dt = Ext.Date.parse(&quot;2006-01-15&quot;, &quot;Y-m-d&quot;);
  609. //dt = Sun Jan 15 2006 15:20:01
  610. dt = Ext.Date.parse(&quot;2006-01-15 3:20:01 PM&quot;, &quot;Y-m-d g:i:s A&quot;);
  611. // attempt to parse Sun Feb 29 2006 03:20:01 in strict mode
  612. dt = Ext.Date.parse(&quot;2006-02-29 03:20:01&quot;, &quot;Y-m-d H:i:s&quot;, true); // returns null
  613. &lt;/code&gt;&lt;/pre&gt;
  614. * @param {String} input The raw date string.
  615. * @param {String} format The expected date string format.
  616. * @param {Boolean} strict (optional) True to validate date strings while parsing (i.e. prevents javascript Date &quot;rollover&quot;)
  617. (defaults to false). Invalid date strings will return null when parsed.
  618. * @return {Date} The parsed Date.
  619. */
  620. parse : function(input, format, strict) {
  621. var p = utilDate.parseFunctions;
  622. if (p[format] == null) {
  623. utilDate.createParser(format);
  624. }
  625. return p[format](input, Ext.isDefined(strict) ? strict : utilDate.useStrict);
  626. },
  627. // Backwards compat
  628. parseDate: function(input, format, strict){
  629. return utilDate.parse(input, format, strict);
  630. },
  631. // private
  632. getFormatCode : function(character) {
  633. var f = utilDate.formatCodes[character];
  634. if (f) {
  635. f = typeof f == 'function'? f() : f;
  636. utilDate.formatCodes[character] = f; // reassign function result to prevent repeated execution
  637. }
  638. // note: unknown characters are treated as literals
  639. return f || (&quot;'&quot; + Ext.String.escape(character) + &quot;'&quot;);
  640. },
  641. // private
  642. createFormat : function(format) {
  643. var code = [],
  644. special = false,
  645. ch = '',
  646. i;
  647. for (i = 0; i &lt; format.length; ++i) {
  648. ch = format.charAt(i);
  649. if (!special &amp;&amp; ch == &quot;\\&quot;) {
  650. special = true;
  651. } else if (special) {
  652. special = false;
  653. code.push(&quot;'&quot; + Ext.String.escape(ch) + &quot;'&quot;);
  654. } else {
  655. code.push(utilDate.getFormatCode(ch));
  656. }
  657. }
  658. utilDate.formatFunctions[format] = Ext.functionFactory(&quot;return &quot; + code.join('+'));
  659. },
  660. // private
  661. createParser : (function() {
  662. var code = [
  663. &quot;var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,&quot;,
  664. &quot;def = Ext.Date.defaults,&quot;,
  665. &quot;results = String(input).match(Ext.Date.parseRegexes[{0}]);&quot;, // either null, or an array of matched strings
  666. &quot;if(results){&quot;,
  667. &quot;{1}&quot;,
  668. &quot;if(u != null){&quot;, // i.e. unix time is defined
  669. &quot;v = new Date(u * 1000);&quot;, // give top priority to UNIX time
  670. &quot;}else{&quot;,
  671. // create Date object representing midnight of the current day;
  672. // this will provide us with our date defaults
  673. // (note: clearTime() handles Daylight Saving Time automatically)
  674. &quot;dt = Ext.Date.clearTime(new Date);&quot;,
  675. // date calculations (note: these calculations create a dependency on Ext.Number.from())
  676. &quot;y = Ext.Number.from(y, Ext.Number.from(def.y, dt.getFullYear()));&quot;,
  677. &quot;m = Ext.Number.from(m, Ext.Number.from(def.m - 1, dt.getMonth()));&quot;,
  678. &quot;d = Ext.Number.from(d, Ext.Number.from(def.d, dt.getDate()));&quot;,
  679. // time calculations (note: these calculations create a dependency on Ext.Number.from())
  680. &quot;h = Ext.Number.from(h, Ext.Number.from(def.h, dt.getHours()));&quot;,
  681. &quot;i = Ext.Number.from(i, Ext.Number.from(def.i, dt.getMinutes()));&quot;,
  682. &quot;s = Ext.Number.from(s, Ext.Number.from(def.s, dt.getSeconds()));&quot;,
  683. &quot;ms = Ext.Number.from(ms, Ext.Number.from(def.ms, dt.getMilliseconds()));&quot;,
  684. &quot;if(z &gt;= 0 &amp;&amp; y &gt;= 0){&quot;,
  685. // both the year and zero-based day of year are defined and &gt;= 0.
  686. // these 2 values alone provide sufficient info to create a full date object
  687. // create Date object representing January 1st for the given year
  688. // handle years &lt; 100 appropriately
  689. &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;,
  690. // then add day of year, checking for Date &quot;rollover&quot; if necessary
  691. &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;,
  692. &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;
  693. &quot;v = null;&quot;, // invalid date, so return null
  694. &quot;}else{&quot;,
  695. // plain old Date object
  696. // handle years &lt; 100 properly
  697. &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;,
  698. &quot;}&quot;,
  699. &quot;}&quot;,
  700. &quot;}&quot;,
  701. &quot;if(v){&quot;,
  702. // favour UTC offset over GMT offset
  703. &quot;if(zz != null){&quot;,
  704. // reset to UTC, then add offset
  705. &quot;v = Ext.Date.add(v, Ext.Date.SECOND, -v.getTimezoneOffset() * 60 - zz);&quot;,
  706. &quot;}else if(o){&quot;,
  707. // reset to GMT, then add offset
  708. &quot;v = Ext.Date.add(v, Ext.Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn));&quot;,
  709. &quot;}&quot;,
  710. &quot;}&quot;,
  711. &quot;return v;&quot;
  712. ].join('\n');
  713. return function(format) {
  714. var regexNum = utilDate.parseRegexes.length,
  715. currentGroup = 1,
  716. calc = [],
  717. regex = [],
  718. special = false,
  719. ch = &quot;&quot;,
  720. i = 0,
  721. len = format.length,
  722. atEnd = [],
  723. obj;
  724. for (; i &lt; len; ++i) {
  725. ch = format.charAt(i);
  726. if (!special &amp;&amp; ch == &quot;\\&quot;) {
  727. special = true;
  728. } else if (special) {
  729. special = false;
  730. regex.push(Ext.String.escape(ch));
  731. } else {
  732. obj = utilDate.formatCodeToRegex(ch, currentGroup);
  733. currentGroup += obj.g;
  734. regex.push(obj.s);
  735. if (obj.g &amp;&amp; obj.c) {
  736. if (obj.calcAtEnd) {
  737. atEnd.push(obj.c);
  738. } else {
  739. calc.push(obj.c);
  740. }
  741. }
  742. }
  743. }
  744. calc = calc.concat(atEnd);
  745. utilDate.parseRegexes[regexNum] = new RegExp(&quot;^&quot; + regex.join('') + &quot;$&quot;, 'i');
  746. utilDate.parseFunctions[format] = Ext.functionFactory(&quot;input&quot;, &quot;strict&quot;, xf(code, regexNum, calc.join('')));
  747. };
  748. }()),
  749. // private
  750. parseCodes : {
  751. /*
  752. * Notes:
  753. * g = {Number} calculation group (0 or 1. only group 1 contributes to date calculations.)
  754. * c = {String} calculation method (required for group 1. null for group 0. {0} = currentGroup - position in regex result array)
  755. * s = {String} regex pattern. all matches are stored in results[], and are accessible by the calculation mapped to 'c'
  756. */
  757. d: {
  758. g:1,
  759. c:&quot;d = parseInt(results[{0}], 10);\n&quot;,
  760. s:&quot;(3[0-1]|[1-2][0-9]|0[1-9])&quot; // day of month with leading zeroes (01 - 31)
  761. },
  762. j: {
  763. g:1,
  764. c:&quot;d = parseInt(results[{0}], 10);\n&quot;,
  765. s:&quot;(3[0-1]|[1-2][0-9]|[1-9])&quot; // day of month without leading zeroes (1 - 31)
  766. },
  767. D: function() {
  768. for (var a = [], i = 0; i &lt; 7; a.push(utilDate.getShortDayName(i)), ++i); // get localised short day names
  769. return {
  770. g:0,
  771. c:null,
  772. s:&quot;(?:&quot; + a.join(&quot;|&quot;) +&quot;)&quot;
  773. };
  774. },
  775. l: function() {
  776. return {
  777. g:0,
  778. c:null,
  779. s:&quot;(?:&quot; + utilDate.dayNames.join(&quot;|&quot;) + &quot;)&quot;
  780. };
  781. },
  782. N: {
  783. g:0,
  784. c:null,
  785. s:&quot;[1-7]&quot; // ISO-8601 day number (1 (monday) - 7 (sunday))
  786. },
  787. //&lt;locale type=&quot;object&quot; property=&quot;parseCodes&quot;&gt;
  788. S: {
  789. g:0,
  790. c:null,
  791. s:&quot;(?:st|nd|rd|th)&quot;
  792. },
  793. //&lt;/locale&gt;
  794. w: {
  795. g:0,
  796. c:null,
  797. s:&quot;[0-6]&quot; // javascript day number (0 (sunday) - 6 (saturday))
  798. },
  799. z: {
  800. g:1,
  801. c:&quot;z = parseInt(results[{0}], 10);\n&quot;,
  802. s:&quot;(\\d{1,3})&quot; // day of the year (0 - 364 (365 in leap years))
  803. },
  804. W: {
  805. g:0,
  806. c:null,
  807. s:&quot;(?:\\d{2})&quot; // ISO-8601 week number (with leading zero)
  808. },
  809. F: function() {
  810. return {
  811. g:1,
  812. c:&quot;m = parseInt(Ext.Date.getMonthNumber(results[{0}]), 10);\n&quot;, // get localised month number
  813. s:&quot;(&quot; + utilDate.monthNames.join(&quot;|&quot;) + &quot;)&quot;
  814. };
  815. },
  816. M: function() {
  817. for (var a = [], i = 0; i &lt; 12; a.push(utilDate.getShortMonthName(i)), ++i); // get localised short month names
  818. return Ext.applyIf({
  819. s:&quot;(&quot; + a.join(&quot;|&quot;) + &quot;)&quot;
  820. }, utilDate.formatCodeToRegex(&quot;F&quot;));
  821. },
  822. m: {
  823. g:1,
  824. c:&quot;m = parseInt(results[{0}], 10) - 1;\n&quot;,
  825. s:&quot;(1[0-2]|0[1-9])&quot; // month number with leading zeros (01 - 12)
  826. },
  827. n: {
  828. g:1,
  829. c:&quot;m = parseInt(results[{0}], 10) - 1;\n&quot;,
  830. s:&quot;(1[0-2]|[1-9])&quot; // month number without leading zeros (1 - 12)
  831. },
  832. t: {
  833. g:0,
  834. c:null,
  835. s:&quot;(?:\\d{2})&quot; // no. of days in the month (28 - 31)
  836. },
  837. L: {
  838. g:0,
  839. c:null,
  840. s:&quot;(?:1|0)&quot;
  841. },
  842. o: function() {
  843. return utilDate.formatCodeToRegex(&quot;Y&quot;);
  844. },
  845. Y: {
  846. g:1,
  847. c:&quot;y = parseInt(results[{0}], 10);\n&quot;,
  848. s:&quot;(\\d{4})&quot; // 4-digit year
  849. },
  850. y: {
  851. g:1,
  852. c:&quot;var ty = parseInt(results[{0}], 10);\n&quot;
  853. + &quot;y = ty &gt; Ext.Date.y2kYear ? 1900 + ty : 2000 + ty;\n&quot;, // 2-digit year
  854. s:&quot;(\\d{1,2})&quot;
  855. },
  856. /*
  857. * In the am/pm parsing routines, we allow both upper and lower case
  858. * even though it doesn't exactly match the spec. It gives much more flexibility
  859. * in being able to specify case insensitive regexes.
  860. */
  861. //&lt;locale type=&quot;object&quot; property=&quot;parseCodes&quot;&gt;
  862. a: {
  863. g:1,
  864. c:&quot;if (/(am)/i.test(results[{0}])) {\n&quot;
  865. + &quot;if (!h || h == 12) { h = 0; }\n&quot;
  866. + &quot;} else { if (!h || h &lt; 12) { h = (h || 0) + 12; }}&quot;,
  867. s:&quot;(am|pm|AM|PM)&quot;,
  868. calcAtEnd: true
  869. },
  870. //&lt;/locale&gt;
  871. //&lt;locale type=&quot;object&quot; property=&quot;parseCodes&quot;&gt;
  872. A: {
  873. g:1,
  874. c:&quot;if (/(am)/i.test(results[{0}])) {\n&quot;
  875. + &quot;if (!h || h == 12) { h = 0; }\n&quot;
  876. + &quot;} else { if (!h || h &lt; 12) { h = (h || 0) + 12; }}&quot;,
  877. s:&quot;(AM|PM|am|pm)&quot;,
  878. calcAtEnd: true
  879. },
  880. //&lt;/locale&gt;
  881. g: {
  882. g:1,
  883. c:&quot;h = parseInt(results[{0}], 10);\n&quot;,
  884. s:&quot;(1[0-2]|[0-9])&quot; // 12-hr format of an hour without leading zeroes (1 - 12)
  885. },
  886. G: {
  887. g:1,
  888. c:&quot;h = parseInt(results[{0}], 10);\n&quot;,
  889. s:&quot;(2[0-3]|1[0-9]|[0-9])&quot; // 24-hr format of an hour without leading zeroes (0 - 23)
  890. },
  891. h: {
  892. g:1,
  893. c:&quot;h = parseInt(results[{0}], 10);\n&quot;,
  894. s:&quot;(1[0-2]|0[1-9])&quot; // 12-hr format of an hour with leading zeroes (01 - 12)
  895. },
  896. H: {
  897. g:1,
  898. c:&quot;h = parseInt(results[{0}], 10);\n&quot;,
  899. s:&quot;(2[0-3]|[0-1][0-9])&quot; // 24-hr format of an hour with leading zeroes (00 - 23)
  900. },
  901. i: {
  902. g:1,
  903. c:&quot;i = parseInt(results[{0}], 10);\n&quot;,
  904. s:&quot;([0-5][0-9])&quot; // minutes with leading zeros (00 - 59)
  905. },
  906. s: {
  907. g:1,
  908. c:&quot;s = parseInt(results[{0}], 10);\n&quot;,
  909. s:&quot;([0-5][0-9])&quot; // seconds with leading zeros (00 - 59)
  910. },
  911. u: {
  912. g:1,
  913. c:&quot;ms = results[{0}]; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n&quot;,
  914. s:&quot;(\\d+)&quot; // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
  915. },
  916. O: {
  917. g:1,
  918. c:[
  919. &quot;o = results[{0}];&quot;,
  920. &quot;var sn = o.substring(0,1),&quot;, // get + / - sign
  921. &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)
  922. &quot;mn = o.substring(3,5) % 60;&quot;, // get minutes
  923. &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
  924. ].join(&quot;\n&quot;),
  925. s: &quot;([+-]\\d{4})&quot; // GMT offset in hrs and mins
  926. },
  927. P: {
  928. g:1,
  929. c:[
  930. &quot;o = results[{0}];&quot;,
  931. &quot;var sn = o.substring(0,1),&quot;, // get + / - sign
  932. &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)
  933. &quot;mn = o.substring(4,6) % 60;&quot;, // get minutes
  934. &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
  935. ].join(&quot;\n&quot;),
  936. s: &quot;([+-]\\d{2}:\\d{2})&quot; // GMT offset in hrs and mins (with colon separator)
  937. },
  938. T: {
  939. g:0,
  940. c:null,
  941. s:&quot;[A-Z]{1,4}&quot; // timezone abbrev. may be between 1 - 4 chars
  942. },
  943. Z: {
  944. g:1,
  945. c:&quot;zz = results[{0}] * 1;\n&quot; // -43200 &lt;= UTC offset &lt;= 50400
  946. + &quot;zz = (-43200 &lt;= zz &amp;&amp; zz &lt;= 50400)? zz : null;\n&quot;,
  947. s:&quot;([+-]?\\d{1,5})&quot; // leading '+' sign is optional for UTC offset
  948. },
  949. c: function() {
  950. var calc = [],
  951. arr = [
  952. utilDate.formatCodeToRegex(&quot;Y&quot;, 1), // year
  953. utilDate.formatCodeToRegex(&quot;m&quot;, 2), // month
  954. utilDate.formatCodeToRegex(&quot;d&quot;, 3), // day
  955. utilDate.formatCodeToRegex(&quot;H&quot;, 4), // hour
  956. utilDate.formatCodeToRegex(&quot;i&quot;, 5), // minute
  957. utilDate.formatCodeToRegex(&quot;s&quot;, 6), // second
  958. {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)
  959. {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
  960. &quot;if(results[8]) {&quot;, // timezone specified
  961. &quot;if(results[8] == 'Z'){&quot;,
  962. &quot;zz = 0;&quot;, // UTC
  963. &quot;}else if (results[8].indexOf(':') &gt; -1){&quot;,
  964. utilDate.formatCodeToRegex(&quot;P&quot;, 8).c, // timezone offset with colon separator
  965. &quot;}else{&quot;,
  966. utilDate.formatCodeToRegex(&quot;O&quot;, 8).c, // timezone offset without colon separator
  967. &quot;}&quot;,
  968. &quot;}&quot;
  969. ].join('\n')}
  970. ],
  971. i,
  972. l;
  973. for (i = 0, l = arr.length; i &lt; l; ++i) {
  974. calc.push(arr[i].c);
  975. }
  976. return {
  977. g:1,
  978. c:calc.join(&quot;&quot;),
  979. s:[
  980. arr[0].s, // year (required)
  981. &quot;(?:&quot;, &quot;-&quot;, arr[1].s, // month (optional)
  982. &quot;(?:&quot;, &quot;-&quot;, arr[2].s, // day (optional)
  983. &quot;(?:&quot;,
  984. &quot;(?:T| )?&quot;, // time delimiter -- either a &quot;T&quot; or a single blank space
  985. 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
  986. &quot;(?::&quot;, arr[5].s, &quot;)?&quot;, // seconds (optional)
  987. &quot;(?:(?:\\.|,)(\\d+))?&quot;, // decimal fraction of a second (e.g. &quot;,12345&quot; or &quot;.98765&quot;) (optional)
  988. &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)
  989. &quot;)?&quot;,
  990. &quot;)?&quot;,
  991. &quot;)?&quot;
  992. ].join(&quot;&quot;)
  993. };
  994. },
  995. U: {
  996. g:1,
  997. c:&quot;u = parseInt(results[{0}], 10);\n&quot;,
  998. s:&quot;(-?\\d+)&quot; // leading minus sign indicates seconds before UNIX epoch
  999. }
  1000. },
  1001. //Old Ext.Date prototype methods.
  1002. // private
  1003. dateFormat: function(date, format) {
  1004. return utilDate.format(date, format);
  1005. },
  1006. <span id='Ext-Date-method-isEqual'> /**
  1007. </span> * Compares if two dates are equal by comparing their values.
  1008. * @param {Date} date1
  1009. * @param {Date} date2
  1010. * @return {Boolean} True if the date values are equal
  1011. */
  1012. isEqual: function(date1, date2) {
  1013. // check we have 2 date objects
  1014. if (date1 &amp;&amp; date2) {
  1015. return (date1.getTime() === date2.getTime());
  1016. }
  1017. // one or both isn't a date, only equal if both are falsey
  1018. return !(date1 || date2);
  1019. },
  1020. <span id='Ext-Date-method-format'> /**
  1021. </span> * Formats a date given the supplied format string.
  1022. * @param {Date} date The date to format
  1023. * @param {String} format The format string
  1024. * @return {String} The formatted date or an empty string if date parameter is not a JavaScript Date object
  1025. */
  1026. format: function(date, format) {
  1027. var formatFunctions = utilDate.formatFunctions;
  1028. if (!Ext.isDate(date)) {
  1029. return '';
  1030. }
  1031. if (formatFunctions[format] == null) {
  1032. utilDate.createFormat(format);
  1033. }
  1034. return formatFunctions[format].call(date) + '';
  1035. },
  1036. <span id='Ext-Date-method-getTimezone'> /**
  1037. </span> * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
  1038. *
  1039. * Note: The date string returned by the javascript Date object's toString() method varies
  1040. * between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America).
  1041. * For a given date string e.g. &quot;Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)&quot;,
  1042. * getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses
  1043. * (which may or may not be present), failing which it proceeds to get the timezone abbreviation
  1044. * from the GMT offset portion of the date string.
  1045. * @param {Date} date The date
  1046. * @return {String} The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).
  1047. */
  1048. getTimezone : function(date) {
  1049. // the following list shows the differences between date strings from different browsers on a WinXP SP2 machine from an Asian locale:
  1050. //
  1051. // Opera : &quot;Thu, 25 Oct 2007 22:53:45 GMT+0800&quot; -- shortest (weirdest) date string of the lot
  1052. // 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)
  1053. // FF : &quot;Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)&quot; -- value in parentheses always gives the correct timezone
  1054. // IE : &quot;Thu Oct 25 22:54:35 UTC+0800 2007&quot; -- (Asian system setting) look for 3-4 letter timezone abbrev
  1055. // IE : &quot;Thu Oct 25 17:06:37 PDT 2007&quot; -- (American system setting) look for 3-4 letter timezone abbrev
  1056. //
  1057. // this crazy regex attempts to guess the correct timezone abbreviation despite these differences.
  1058. // step 1: (?:\((.*)\) -- find timezone in parentheses
  1059. // 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
  1060. // step 3: remove all non uppercase characters found in step 1 and 2
  1061. return date.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, &quot;$1$2&quot;).replace(/[^A-Z]/g, &quot;&quot;);
  1062. },
  1063. <span id='Ext-Date-method-getGMTOffset'> /**
  1064. </span> * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
  1065. * @param {Date} date The date
  1066. * @param {Boolean} colon (optional) true to separate the hours and minutes with a colon (defaults to false).
  1067. * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600').
  1068. */
  1069. getGMTOffset : function(date, colon) {
  1070. var offset = date.getTimezoneOffset();
  1071. return (offset &gt; 0 ? &quot;-&quot; : &quot;+&quot;)
  1072. + Ext.String.leftPad(Math.floor(Math.abs(offset) / 60), 2, &quot;0&quot;)
  1073. + (colon ? &quot;:&quot; : &quot;&quot;)
  1074. + Ext.String.leftPad(Math.abs(offset % 60), 2, &quot;0&quot;);
  1075. },
  1076. <span id='Ext-Date-method-getDayOfYear'> /**
  1077. </span> * Get the numeric day number of the year, adjusted for leap year.
  1078. * @param {Date} date The date
  1079. * @return {Number} 0 to 364 (365 in leap years).
  1080. */
  1081. getDayOfYear: function(date) {
  1082. var num = 0,
  1083. d = Ext.Date.clone(date),
  1084. m = date.getMonth(),
  1085. i;
  1086. for (i = 0, d.setDate(1), d.setMonth(0); i &lt; m; d.setMonth(++i)) {
  1087. num += utilDate.getDaysInMonth(d);
  1088. }
  1089. return num + date.getDate() - 1;
  1090. },
  1091. <span id='Ext-Date-method-getWeekOfYear'> /**
  1092. </span> * Get the numeric ISO-8601 week number of the year.
  1093. * (equivalent to the format specifier 'W', but without a leading zero).
  1094. * @param {Date} date The date
  1095. * @return {Number} 1 to 53
  1096. * @method
  1097. */
  1098. getWeekOfYear : (function() {
  1099. // adapted from http://www.merlyn.demon.co.uk/weekcalc.htm
  1100. var ms1d = 864e5, // milliseconds in a day
  1101. ms7d = 7 * ms1d; // milliseconds in a week
  1102. return function(date) { // return a closure so constants get calculated only once
  1103. var DC3 = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate() + 3) / ms1d, // an Absolute Day Number
  1104. AWN = Math.floor(DC3 / 7), // an Absolute Week Number
  1105. Wyr = new Date(AWN * ms7d).getUTCFullYear();
  1106. return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
  1107. };
  1108. }()),
  1109. <span id='Ext-Date-method-isLeapYear'> /**
  1110. </span> * Checks if the current date falls within a leap year.
  1111. * @param {Date} date The date
  1112. * @return {Boolean} True if the current date falls within a leap year, false otherwise.
  1113. */
  1114. isLeapYear : function(date) {
  1115. var year = date.getFullYear();
  1116. return !!((year &amp; 3) == 0 &amp;&amp; (year % 100 || (year % 400 == 0 &amp;&amp; year)));
  1117. },
  1118. <span id='Ext-Date-method-getFirstDayOfMonth'> /**
  1119. </span> * Get the first day of the current month, adjusted for leap year. The returned value
  1120. * is the numeric day index within the week (0-6) which can be used in conjunction with
  1121. * the {@link #monthNames} array to retrieve the textual day name.
  1122. * Example:
  1123. * &lt;pre&gt;&lt;code&gt;
  1124. var dt = new Date('1/10/2007'),
  1125. firstDay = Ext.Date.getFirstDayOfMonth(dt);
  1126. console.log(Ext.Date.dayNames[firstDay]); //output: 'Monday'
  1127. * &lt;/code&gt;&lt;/pre&gt;
  1128. * @param {Date} date The date
  1129. * @return {Number} The day number (0-6).
  1130. */
  1131. getFirstDayOfMonth : function(date) {
  1132. var day = (date.getDay() - (date.getDate() - 1)) % 7;
  1133. return (day &lt; 0) ? (day + 7) : day;
  1134. },
  1135. <span id='Ext-Date-method-getLastDayOfMonth'> /**
  1136. </span> * Get the last day of the current month, adjusted for leap year. The returned value
  1137. * is the numeric day index within the week (0-6) which can be used in conjunction with
  1138. * the {@link #monthNames} array to retrieve the textual day name.
  1139. * Example:
  1140. * &lt;pre&gt;&lt;code&gt;
  1141. var dt = new Date('1/10/2007'),
  1142. lastDay = Ext.Date.getLastDayOfMonth(dt);
  1143. console.log(Ext.Date.dayNames[lastDay]); //output: 'Wednesday'
  1144. * &lt;/code&gt;&lt;/pre&gt;
  1145. * @param {Date} date The date
  1146. * @return {Number} The day number (0-6).
  1147. */
  1148. getLastDayOfMonth : function(date) {
  1149. return utilDate.getLastDateOfMonth(date).getDay();
  1150. },
  1151. <span id='Ext-Date-method-getFirstDateOfMonth'> /**
  1152. </span> * Get the date of the first day of the month in which this date resides.
  1153. * @param {Date} date The date
  1154. * @return {Date}
  1155. */
  1156. getFirstDateOfMonth : function(date) {
  1157. return new Date(date.getFullYear(), date.getMonth(), 1);
  1158. },
  1159. <span id='Ext-Date-method-getLastDateOfMonth'> /**
  1160. </span> * Get the date of the last day of the month in which this date resides.
  1161. * @param {Date} date The date
  1162. * @return {Date}
  1163. */
  1164. getLastDateOfMonth : function(date) {
  1165. return new Date(date.getFullYear(), date.getMonth(), utilDate.getDaysInMonth(date));
  1166. },
  1167. <span id='Ext-Date-method-getDaysInMonth'> /**
  1168. </span> * Get the number of days in the current month, adjusted for leap year.
  1169. * @param {Date} date The date
  1170. * @return {Number} The number of days in the month.
  1171. * @method
  1172. */
  1173. getDaysInMonth: (function() {
  1174. var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  1175. return function(date) { // return a closure for efficiency
  1176. var m = date.getMonth();
  1177. return m == 1 &amp;&amp; utilDate.isLeapYear(date) ? 29 : daysInMonth[m];
  1178. };
  1179. }()),
  1180. //&lt;locale type=&quot;function&quot;&gt;
  1181. <span id='Ext-Date-method-getSuffix'> /**
  1182. </span> * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
  1183. * @param {Date} date The date
  1184. * @return {String} 'st, 'nd', 'rd' or 'th'.
  1185. */
  1186. getSuffix : function(date) {
  1187. switch (date.getDate()) {
  1188. case 1:
  1189. case 21:
  1190. case 31:
  1191. return &quot;st&quot;;
  1192. case 2:
  1193. case 22:
  1194. return &quot;nd&quot;;
  1195. case 3:
  1196. case 23:
  1197. return &quot;rd&quot;;
  1198. default:
  1199. return &quot;th&quot;;
  1200. }
  1201. },
  1202. //&lt;/locale&gt;
  1203. <span id='Ext-Date-method-clone'> /**
  1204. </span> * Creates and returns a new Date instance with the exact same date value as the called instance.
  1205. * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
  1206. * variable will also be changed. When the intention is to create a new variable that will not
  1207. * modify the original instance, you should create a clone.
  1208. *
  1209. * Example of correctly cloning a date:
  1210. * &lt;pre&gt;&lt;code&gt;
  1211. //wrong way:
  1212. var orig = new Date('10/1/2006');
  1213. var copy = orig;
  1214. copy.setDate(5);
  1215. console.log(orig); //returns 'Thu Oct 05 2006'!
  1216. //correct way:
  1217. var orig = new Date('10/1/2006'),
  1218. copy = Ext.Date.clone(orig);
  1219. copy.setDate(5);
  1220. console.log(orig); //returns 'Thu Oct 01 2006'
  1221. * &lt;/code&gt;&lt;/pre&gt;
  1222. * @param {Date} date The date
  1223. * @return {Date} The new Date instance.
  1224. */
  1225. clone : function(date) {
  1226. return new Date(date.getTime());
  1227. },
  1228. <span id='Ext-Date-method-isDST'> /**
  1229. </span> * Checks if the current date is affected by Daylight Saving Time (DST).
  1230. * @param {Date} date The date
  1231. * @return {Boolean} True if the current date is affected by DST.
  1232. */
  1233. isDST : function(date) {
  1234. // adapted from http://sencha.com/forum/showthread.php?p=247172#post247172
  1235. // courtesy of @geoffrey.mcgill
  1236. return new Date(date.getFullYear(), 0, 1).getTimezoneOffset() != date.getTimezoneOffset();
  1237. },
  1238. <span id='Ext-Date-method-clearTime'> /**
  1239. </span> * Attempts to clear all time information from this Date by setting the time to midnight of the same day,
  1240. * automatically adjusting for Daylight Saving Time (DST) where applicable.
  1241. * (note: DST timezone information for the browser's host operating system is assumed to be up-to-date)
  1242. * @param {Date} date The date
  1243. * @param {Boolean} clone true to create a clone of this date, clear the time and return it (defaults to false).
  1244. * @return {Date} this or the clone.
  1245. */
  1246. clearTime : function(date, clone) {
  1247. if (clone) {
  1248. return Ext.Date.clearTime(Ext.Date.clone(date));
  1249. }
  1250. // get current date before clearing time
  1251. var d = date.getDate(),
  1252. hr,
  1253. c;
  1254. // clear time
  1255. date.setHours(0);
  1256. date.setMinutes(0);
  1257. date.setSeconds(0);
  1258. date.setMilliseconds(0);
  1259. if (date.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
  1260. // note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the case)
  1261. // refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
  1262. // increment hour until cloned date == current date
  1263. for (hr = 1, c = utilDate.add(date, Ext.Date.HOUR, hr); c.getDate() != d; hr++, c = utilDate.add(date, Ext.Date.HOUR, hr));
  1264. date.setDate(d);
  1265. date.setHours(c.getHours());
  1266. }
  1267. return date;
  1268. },
  1269. <span id='Ext-Date-method-add'> /**
  1270. </span> * Provides a convenient method for performing basic date arithmetic. This method
  1271. * does not modify the Date instance being called - it creates and returns
  1272. * a new Date instance containing the resulting date value.
  1273. *
  1274. * Examples:
  1275. * &lt;pre&gt;&lt;code&gt;
  1276. // Basic usage:
  1277. var dt = Ext.Date.add(new Date('10/29/2006'), Ext.Date.DAY, 5);
  1278. console.log(dt); //returns 'Fri Nov 03 2006 00:00:00'
  1279. // Negative values will be subtracted:
  1280. var dt2 = Ext.Date.add(new Date('10/1/2006'), Ext.Date.DAY, -5);
  1281. console.log(dt2); //returns 'Tue Sep 26 2006 00:00:00'
  1282. * &lt;/code&gt;&lt;/pre&gt;
  1283. *
  1284. * @param {Date} date The date to modify
  1285. * @param {String} interval A valid date interval enum value.
  1286. * @param {Number} value The amount to add to the current date.
  1287. * @return {Date} The new Date instance.
  1288. */
  1289. add : function(date, interval, value) {
  1290. var d = Ext.Date.clone(date),
  1291. Date = Ext.Date,
  1292. day;
  1293. if (!interval || value === 0) {
  1294. return d;
  1295. }
  1296. switch(interval.toLowerCase()) {
  1297. case Ext.Date.MILLI:
  1298. d.setMilliseconds(d.getMilliseconds() + value);
  1299. break;
  1300. case Ext.Date.SECOND:
  1301. d.setSeconds(d.getSeconds() + value);
  1302. break;
  1303. case Ext.Date.MINUTE:
  1304. d.setMinutes(d.getMinutes() + value);
  1305. break;
  1306. case Ext.Date.HOUR:
  1307. d.setHours(d.getHours() + value);
  1308. break;
  1309. case Ext.Date.DAY:
  1310. d.setDate(d.getDate() + value);
  1311. break;
  1312. case Ext.Date.MONTH:
  1313. day = date.getDate();
  1314. if (day &gt; 28) {
  1315. day = Math.min(day, Ext.Date.getLastDateOfMonth(Ext.Date.add(Ext.Date.getFirstDateOfMonth(date), Ext.Date.MONTH, value)).getDate());
  1316. }
  1317. d.setDate(day);
  1318. d.setMonth(date.getMonth() + value);
  1319. break;
  1320. case Ext.Date.YEAR:
  1321. day = date.getDate();
  1322. if (day &gt; 28) {
  1323. day = Math.min(day, Ext.Date.getLastDateOfMonth(Ext.Date.add(Ext.Date.getFirstDateOfMonth(date), Ext.Date.YEAR, value)).getDate());
  1324. }
  1325. d.setDate(day);
  1326. d.setFullYear(date.getFullYear() + value);
  1327. break;
  1328. }
  1329. return d;
  1330. },
  1331. <span id='Ext-Date-method-between'> /**
  1332. </span> * Checks if a date falls on or between the given start and end dates.
  1333. * @param {Date} date The date to check
  1334. * @param {Date} start Start date
  1335. * @param {Date} end End date
  1336. * @return {Boolean} true if this date falls on or between the given start and end dates.
  1337. */
  1338. between : function(date, start, end) {
  1339. var t = date.getTime();
  1340. return start.getTime() &lt;= t &amp;&amp; t &lt;= end.getTime();
  1341. },
  1342. //Maintains compatibility with old static and prototype window.Date methods.
  1343. compat: function() {
  1344. var nativeDate = window.Date,
  1345. p, u,
  1346. 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'],
  1347. proto = ['dateFormat', 'format', 'getTimezone', 'getGMTOffset', 'getDayOfYear', 'getWeekOfYear', 'isLeapYear', 'getFirstDayOfMonth', 'getLastDayOfMonth', 'getDaysInMonth', 'getSuffix', 'clone', 'isDST', 'clearTime', 'add', 'between'],
  1348. sLen = statics.length,
  1349. pLen = proto.length,
  1350. stat, prot, s;
  1351. //Append statics
  1352. for (s = 0; s &lt; sLen; s++) {
  1353. stat = statics[s];
  1354. nativeDate[stat] = utilDate[stat];
  1355. }
  1356. //Append to prototype
  1357. for (p = 0; p &lt; pLen; p++) {
  1358. prot = proto[p];
  1359. nativeDate.prototype[prot] = function() {
  1360. var args = Array.prototype.slice.call(arguments);
  1361. args.unshift(this);
  1362. return utilDate[prot].apply(utilDate, args);
  1363. };
  1364. }
  1365. }
  1366. };
  1367. var utilDate = Ext.Date;
  1368. }());
  1369. </pre>
  1370. </body>
  1371. </html>