Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1344 lines
57 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Date"></div>/**
  16. * @class Date
  17. *
  18. * The date parsing and formatting syntax contains a subset of
  19. * <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
  20. * supported will provide results equivalent to their PHP versions.
  21. *
  22. * The following is a list of all currently supported formats:
  23. * <pre>
  24. Format Description Example returned values
  25. ------ ----------------------------------------------------------------------- -----------------------
  26. d Day of the month, 2 digits with leading zeros 01 to 31
  27. D A short textual representation of the day of the week Mon to Sun
  28. j Day of the month without leading zeros 1 to 31
  29. l A full textual representation of the day of the week Sunday to Saturday
  30. N ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
  31. S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
  32. w Numeric representation of the day of the week 0 (for Sunday) to 6 (for Saturday)
  33. z The day of the year (starting from 0) 0 to 364 (365 in leap years)
  34. W ISO-8601 week number of year, weeks starting on Monday 01 to 53
  35. F A full textual representation of a month, such as January or March January to December
  36. m Numeric representation of a month, with leading zeros 01 to 12
  37. M A short textual representation of a month Jan to Dec
  38. n Numeric representation of a month, without leading zeros 1 to 12
  39. t Number of days in the given month 28 to 31
  40. L Whether it's a leap year 1 if it is a leap year, 0 otherwise.
  41. o ISO-8601 year number (identical to (Y), but if the ISO week number (W) Examples: 1998 or 2004
  42. belongs to the previous or next year, that year is used instead)
  43. Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
  44. y A two digit representation of a year Examples: 99 or 03
  45. a Lowercase Ante meridiem and Post meridiem am or pm
  46. A Uppercase Ante meridiem and Post meridiem AM or PM
  47. g 12-hour format of an hour without leading zeros 1 to 12
  48. G 24-hour format of an hour without leading zeros 0 to 23
  49. h 12-hour format of an hour with leading zeros 01 to 12
  50. H 24-hour format of an hour with leading zeros 00 to 23
  51. i Minutes, with leading zeros 00 to 59
  52. s Seconds, with leading zeros 00 to 59
  53. u Decimal fraction of a second Examples:
  54. (minimum 1 digit, arbitrary number of digits allowed) 001 (i.e. 0.001s) or
  55. 100 (i.e. 0.100s) or
  56. 999 (i.e. 0.999s) or
  57. 999876543210 (i.e. 0.999876543210s)
  58. O Difference to Greenwich time (GMT) in hours and minutes Example: +1030
  59. P Difference to Greenwich time (GMT) with colon between hours and minutes Example: -08:00
  60. T Timezone abbreviation of the machine running the code Examples: EST, MDT, PDT ...
  61. Z Timezone offset in seconds (negative if west of UTC, positive if east) -43200 to 50400
  62. c ISO 8601 date
  63. Notes: Examples:
  64. 1) If unspecified, the month / day defaults to the current month / day, 1991 or
  65. the time defaults to midnight, while the timezone defaults to the 1992-10 or
  66. browser's timezone. If a time is specified, it must include both hours 1993-09-20 or
  67. and minutes. The "T" delimiter, seconds, milliseconds and timezone 1994-08-19T16:20+01:00 or
  68. are optional. 1995-07-18T17:21:28-02:00 or
  69. 2) The decimal fraction of a second, if specified, must contain at 1996-06-17T18:22:29.98765+03:00 or
  70. least 1 digit (there is no limit to the maximum number 1997-05-16T19:23:30,12345-0400 or
  71. of digits allowed), and may be delimited by either a '.' or a ',' 1998-04-15T20:24:31.2468Z or
  72. Refer to the examples on the right for the various levels of 1999-03-14T20:24:32Z or
  73. date-time granularity which are supported, or see 2000-02-13T21:25:33
  74. http://www.w3.org/TR/NOTE-datetime for more info. 2001-01-12 22:26:34
  75. U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1193432466 or -2138434463
  76. M$ Microsoft AJAX serialized dates \/Date(1238606590509)\/ (i.e. UTC milliseconds since epoch) or
  77. \/Date(1238606590509+0800)\/
  78. </pre>
  79. *
  80. * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
  81. * <pre><code>
  82. // Sample date:
  83. // 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
  84. var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
  85. document.write(dt.format('Y-m-d')); // 2007-01-10
  86. document.write(dt.format('F j, Y, g:i a')); // January 10, 2007, 3:05 pm
  87. document.write(dt.format('l, \\t\\he jS \\of F Y h:i:s A')); // Wednesday, the 10th of January 2007 03:05:01 PM
  88. </code></pre>
  89. *
  90. * Here are some standard date/time patterns that you might find helpful. They
  91. * are not part of the source of Date.js, but to use them you can simply copy this
  92. * block of code into any script that is included after Date.js and they will also become
  93. * globally available on the Date object. Feel free to add or remove patterns as needed in your code.
  94. * <pre><code>
  95. Date.patterns = {
  96. ISO8601Long:"Y-m-d H:i:s",
  97. ISO8601Short:"Y-m-d",
  98. ShortDate: "n/j/Y",
  99. LongDate: "l, F d, Y",
  100. FullDateTime: "l, F d, Y g:i:s A",
  101. MonthDay: "F d",
  102. ShortTime: "g:i A",
  103. LongTime: "g:i:s A",
  104. SortableDateTime: "Y-m-d\\TH:i:s",
  105. UniversalSortableDateTime: "Y-m-d H:i:sO",
  106. YearMonth: "F, Y"
  107. };
  108. </code></pre>
  109. *
  110. * Example usage:
  111. * <pre><code>
  112. var dt = new Date();
  113. document.write(dt.format(Date.patterns.ShortDate));
  114. </code></pre>
  115. * <p>Developer-written, custom formats may be used by supplying both a formatting and a parsing function
  116. * which perform to specialized requirements. The functions are stored in {@link #parseFunctions} and {@link #formatFunctions}.</p>
  117. */
  118. /*
  119. * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
  120. * (see http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/)
  121. * They generate precompiled functions from format patterns instead of parsing and
  122. * processing each pattern every time a date is formatted. These functions are available
  123. * on every Date object.
  124. */
  125. (function() {
  126. <div id="prop-Date-useStrict"></div>/**
  127. * Global flag which determines if strict date parsing should be used.
  128. * Strict date parsing will not roll-over invalid dates, which is the
  129. * default behaviour of javascript Date objects.
  130. * (see {@link #parseDate} for more information)
  131. * Defaults to <tt>false</tt>.
  132. * @static
  133. * @type Boolean
  134. */
  135. Date.useStrict = false;
  136. // create private copy of Ext's String.format() method
  137. // - to remove unnecessary dependency
  138. // - to resolve namespace conflict with M$-Ajax's implementation
  139. function xf(format) {
  140. var args = Array.prototype.slice.call(arguments, 1);
  141. return format.replace(/\{(\d+)\}/g, function(m, i) {
  142. return args[i];
  143. });
  144. }
  145. // private
  146. Date.formatCodeToRegex = function(character, currentGroup) {
  147. // Note: currentGroup - position in regex result array (see notes for Date.parseCodes below)
  148. var p = Date.parseCodes[character];
  149. if (p) {
  150. p = typeof p == 'function'? p() : p;
  151. Date.parseCodes[character] = p; // reassign function result to prevent repeated execution
  152. }
  153. return p ? Ext.applyIf({
  154. c: p.c ? xf(p.c, currentGroup || "{0}") : p.c
  155. }, p) : {
  156. g:0,
  157. c:null,
  158. s:Ext.escapeRe(character) // treat unrecognised characters as literals
  159. };
  160. };
  161. // private shorthand for Date.formatCodeToRegex since we'll be using it fairly often
  162. var $f = Date.formatCodeToRegex;
  163. Ext.apply(Date, {
  164. <div id="prop-Date-parseFunctions"></div>/**
  165. * <p>An object hash in which each property is a date parsing function. The property name is the
  166. * format string which that function parses.</p>
  167. * <p>This object is automatically populated with date parsing functions as
  168. * date formats are requested for Ext standard formatting strings.</p>
  169. * <p>Custom parsing functions may be inserted into this object, keyed by a name which from then on
  170. * may be used as a format string to {@link #parseDate}.<p>
  171. * <p>Example:</p><pre><code>
  172. Date.parseFunctions['x-date-format'] = myDateParser;
  173. </code></pre>
  174. * <p>A parsing function should return a Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
  175. * <li><code>date</code> : String<div class="sub-desc">The date string to parse.</div></li>
  176. * <li><code>strict</code> : Boolean<div class="sub-desc">True to validate date strings while parsing
  177. * (i.e. prevent javascript Date "rollover") (The default must be false).
  178. * Invalid date strings should return null when parsed.</div></li>
  179. * </ul></div></p>
  180. * <p>To enable Dates to also be <i>formatted</i> according to that format, a corresponding
  181. * formatting function must be placed into the {@link #formatFunctions} property.
  182. * @property parseFunctions
  183. * @static
  184. * @type Object
  185. */
  186. parseFunctions: {
  187. "M$": function(input, strict) {
  188. // note: the timezone offset is ignored since the M$ Ajax server sends
  189. // a UTC milliseconds-since-Unix-epoch value (negative values are allowed)
  190. var re = new RegExp('\\/Date\\(([-+])?(\\d+)(?:[+-]\\d{4})?\\)\\/');
  191. var r = (input || '').match(re);
  192. return r? new Date(((r[1] || '') + r[2]) * 1) : null;
  193. }
  194. },
  195. parseRegexes: [],
  196. <div id="prop-Date-formatFunctions"></div>/**
  197. * <p>An object hash in which each property is a date formatting function. The property name is the
  198. * format string which corresponds to the produced formatted date string.</p>
  199. * <p>This object is automatically populated with date formatting functions as
  200. * date formats are requested for Ext standard formatting strings.</p>
  201. * <p>Custom formatting functions may be inserted into this object, keyed by a name which from then on
  202. * may be used as a format string to {@link #format}. Example:</p><pre><code>
  203. Date.formatFunctions['x-date-format'] = myDateFormatter;
  204. </code></pre>
  205. * <p>A formatting function should return a string representation of the passed Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
  206. * <li><code>date</code> : Date<div class="sub-desc">The Date to format.</div></li>
  207. * </ul></div></p>
  208. * <p>To enable date strings to also be <i>parsed</i> according to that format, a corresponding
  209. * parsing function must be placed into the {@link #parseFunctions} property.
  210. * @property formatFunctions
  211. * @static
  212. * @type Object
  213. */
  214. formatFunctions: {
  215. "M$": function() {
  216. // UTC milliseconds since Unix epoch (M$-AJAX serialized date format (MRSF))
  217. return '\\/Date(' + this.getTime() + ')\\/';
  218. }
  219. },
  220. y2kYear : 50,
  221. <div id="prop-Date-MILLI"></div>/**
  222. * Date interval constant
  223. * @static
  224. * @type String
  225. */
  226. MILLI : "ms",
  227. <div id="prop-Date-SECOND"></div>/**
  228. * Date interval constant
  229. * @static
  230. * @type String
  231. */
  232. SECOND : "s",
  233. <div id="prop-Date-MINUTE"></div>/**
  234. * Date interval constant
  235. * @static
  236. * @type String
  237. */
  238. MINUTE : "mi",
  239. <div id="prop-Date-HOUR"></div>/** Date interval constant
  240. * @static
  241. * @type String
  242. */
  243. HOUR : "h",
  244. <div id="prop-Date-DAY"></div>/**
  245. * Date interval constant
  246. * @static
  247. * @type String
  248. */
  249. DAY : "d",
  250. <div id="prop-Date-MONTH"></div>/**
  251. * Date interval constant
  252. * @static
  253. * @type String
  254. */
  255. MONTH : "mo",
  256. <div id="prop-Date-YEAR"></div>/**
  257. * Date interval constant
  258. * @static
  259. * @type String
  260. */
  261. YEAR : "y",
  262. <div id="prop-Date-defaults"></div>/**
  263. * <p>An object hash containing default date values used during date parsing.</p>
  264. * <p>The following properties are available:<div class="mdetail-params"><ul>
  265. * <li><code>y</code> : Number<div class="sub-desc">The default year value. (defaults to undefined)</div></li>
  266. * <li><code>m</code> : Number<div class="sub-desc">The default 1-based month value. (defaults to undefined)</div></li>
  267. * <li><code>d</code> : Number<div class="sub-desc">The default day value. (defaults to undefined)</div></li>
  268. * <li><code>h</code> : Number<div class="sub-desc">The default hour value. (defaults to undefined)</div></li>
  269. * <li><code>i</code> : Number<div class="sub-desc">The default minute value. (defaults to undefined)</div></li>
  270. * <li><code>s</code> : Number<div class="sub-desc">The default second value. (defaults to undefined)</div></li>
  271. * <li><code>ms</code> : Number<div class="sub-desc">The default millisecond value. (defaults to undefined)</div></li>
  272. * </ul></div></p>
  273. * <p>Override these properties to customize the default date values used by the {@link #parseDate} method.</p>
  274. * <p><b>Note: In countries which experience Daylight Saving Time (i.e. DST), the <tt>h</tt>, <tt>i</tt>, <tt>s</tt>
  275. * and <tt>ms</tt> properties may coincide with the exact time in which DST takes effect.
  276. * It is the responsiblity of the developer to account for this.</b></p>
  277. * Example Usage:
  278. * <pre><code>
  279. // set default day value to the first day of the month
  280. Date.defaults.d = 1;
  281. // parse a February date string containing only year and month values.
  282. // setting the default day value to 1 prevents weird date rollover issues
  283. // when attempting to parse the following date string on, for example, March 31st 2009.
  284. Date.parseDate('2009-02', 'Y-m'); // returns a Date object representing February 1st 2009
  285. </code></pre>
  286. * @property defaults
  287. * @static
  288. * @type Object
  289. */
  290. defaults: {},
  291. <div id="prop-Date-dayNames"></div>/**
  292. * An array of textual day names.
  293. * Override these values for international dates.
  294. * Example:
  295. * <pre><code>
  296. Date.dayNames = [
  297. 'SundayInYourLang',
  298. 'MondayInYourLang',
  299. ...
  300. ];
  301. </code></pre>
  302. * @type Array
  303. * @static
  304. */
  305. dayNames : [
  306. "Sunday",
  307. "Monday",
  308. "Tuesday",
  309. "Wednesday",
  310. "Thursday",
  311. "Friday",
  312. "Saturday"
  313. ],
  314. <div id="prop-Date-monthNames"></div>/**
  315. * An array of textual month names.
  316. * Override these values for international dates.
  317. * Example:
  318. * <pre><code>
  319. Date.monthNames = [
  320. 'JanInYourLang',
  321. 'FebInYourLang',
  322. ...
  323. ];
  324. </code></pre>
  325. * @type Array
  326. * @static
  327. */
  328. monthNames : [
  329. "January",
  330. "February",
  331. "March",
  332. "April",
  333. "May",
  334. "June",
  335. "July",
  336. "August",
  337. "September",
  338. "October",
  339. "November",
  340. "December"
  341. ],
  342. <div id="prop-Date-monthNumbers"></div>/**
  343. * An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are case-sensitive).
  344. * Override these values for international dates.
  345. * Example:
  346. * <pre><code>
  347. Date.monthNumbers = {
  348. 'ShortJanNameInYourLang':0,
  349. 'ShortFebNameInYourLang':1,
  350. ...
  351. };
  352. </code></pre>
  353. * @type Object
  354. * @static
  355. */
  356. monthNumbers : {
  357. Jan:0,
  358. Feb:1,
  359. Mar:2,
  360. Apr:3,
  361. May:4,
  362. Jun:5,
  363. Jul:6,
  364. Aug:7,
  365. Sep:8,
  366. Oct:9,
  367. Nov:10,
  368. Dec:11
  369. },
  370. <div id="method-Date-getShortMonthName"></div>/**
  371. * Get the short month name for the given month number.
  372. * Override this function for international dates.
  373. * @param {Number} month A zero-based javascript month number.
  374. * @return {String} The short month name.
  375. * @static
  376. */
  377. getShortMonthName : function(month) {
  378. return Date.monthNames[month].substring(0, 3);
  379. },
  380. <div id="method-Date-getShortDayName"></div>/**
  381. * Get the short day name for the given day number.
  382. * Override this function for international dates.
  383. * @param {Number} day A zero-based javascript day number.
  384. * @return {String} The short day name.
  385. * @static
  386. */
  387. getShortDayName : function(day) {
  388. return Date.dayNames[day].substring(0, 3);
  389. },
  390. <div id="method-Date-getMonthNumber"></div>/**
  391. * Get the zero-based javascript month number for the given short/full month name.
  392. * Override this function for international dates.
  393. * @param {String} name The short/full month name.
  394. * @return {Number} The zero-based javascript month number.
  395. * @static
  396. */
  397. getMonthNumber : function(name) {
  398. // handle camel casing for english month names (since the keys for the Date.monthNumbers hash are case sensitive)
  399. return Date.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()];
  400. },
  401. <div id="prop-Date-formatCodes"></div>/**
  402. * The base format-code to formatting-function hashmap used by the {@link #format} method.
  403. * Formatting functions are strings (or functions which return strings) which
  404. * will return the appropriate value when evaluated in the context of the Date object
  405. * from which the {@link #format} method is called.
  406. * Add to / override these mappings for custom date formatting.
  407. * Note: Date.format() treats characters as literals if an appropriate mapping cannot be found.
  408. * Example:
  409. * <pre><code>
  410. Date.formatCodes.x = "String.leftPad(this.getDate(), 2, '0')";
  411. (new Date()).format("X"); // returns the current day of the month
  412. </code></pre>
  413. * @type Object
  414. * @static
  415. */
  416. formatCodes : {
  417. d: "String.leftPad(this.getDate(), 2, '0')",
  418. D: "Date.getShortDayName(this.getDay())", // get localised short day name
  419. j: "this.getDate()",
  420. l: "Date.dayNames[this.getDay()]",
  421. N: "(this.getDay() ? this.getDay() : 7)",
  422. S: "this.getSuffix()",
  423. w: "this.getDay()",
  424. z: "this.getDayOfYear()",
  425. W: "String.leftPad(this.getWeekOfYear(), 2, '0')",
  426. F: "Date.monthNames[this.getMonth()]",
  427. m: "String.leftPad(this.getMonth() + 1, 2, '0')",
  428. M: "Date.getShortMonthName(this.getMonth())", // get localised short month name
  429. n: "(this.getMonth() + 1)",
  430. t: "this.getDaysInMonth()",
  431. L: "(this.isLeapYear() ? 1 : 0)",
  432. o: "(this.getFullYear() + (this.getWeekOfYear() == 1 && this.getMonth() > 0 ? +1 : (this.getWeekOfYear() >= 52 && this.getMonth() < 11 ? -1 : 0)))",
  433. Y: "String.leftPad(this.getFullYear(), 4, '0')",
  434. y: "('' + this.getFullYear()).substring(2, 4)",
  435. a: "(this.getHours() < 12 ? 'am' : 'pm')",
  436. A: "(this.getHours() < 12 ? 'AM' : 'PM')",
  437. g: "((this.getHours() % 12) ? this.getHours() % 12 : 12)",
  438. G: "this.getHours()",
  439. h: "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')",
  440. H: "String.leftPad(this.getHours(), 2, '0')",
  441. i: "String.leftPad(this.getMinutes(), 2, '0')",
  442. s: "String.leftPad(this.getSeconds(), 2, '0')",
  443. u: "String.leftPad(this.getMilliseconds(), 3, '0')",
  444. O: "this.getGMTOffset()",
  445. P: "this.getGMTOffset(true)",
  446. T: "this.getTimezone()",
  447. Z: "(this.getTimezoneOffset() * -60)",
  448. c: function() { // ISO-8601 -- GMT format
  449. for (var c = "Y-m-dTH:i:sP", code = [], i = 0, l = c.length; i < l; ++i) {
  450. var e = c.charAt(i);
  451. code.push(e == "T" ? "'T'" : Date.getFormatCode(e)); // treat T as a character literal
  452. }
  453. return code.join(" + ");
  454. },
  455. /*
  456. c: function() { // ISO-8601 -- UTC format
  457. return [
  458. "this.getUTCFullYear()", "'-'",
  459. "String.leftPad(this.getUTCMonth() + 1, 2, '0')", "'-'",
  460. "String.leftPad(this.getUTCDate(), 2, '0')",
  461. "'T'",
  462. "String.leftPad(this.getUTCHours(), 2, '0')", "':'",
  463. "String.leftPad(this.getUTCMinutes(), 2, '0')", "':'",
  464. "String.leftPad(this.getUTCSeconds(), 2, '0')",
  465. "'Z'"
  466. ].join(" + ");
  467. },
  468. */
  469. U: "Math.round(this.getTime() / 1000)"
  470. },
  471. <div id="method-Date-isValid"></div>/**
  472. * Checks if the passed Date parameters will cause a javascript Date "rollover".
  473. * @param {Number} year 4-digit year
  474. * @param {Number} month 1-based month-of-year
  475. * @param {Number} day Day of month
  476. * @param {Number} hour (optional) Hour
  477. * @param {Number} minute (optional) Minute
  478. * @param {Number} second (optional) Second
  479. * @param {Number} millisecond (optional) Millisecond
  480. * @return {Boolean} true if the passed parameters do not cause a Date "rollover", false otherwise.
  481. * @static
  482. */
  483. isValid : function(y, m, d, h, i, s, ms) {
  484. // setup defaults
  485. h = h || 0;
  486. i = i || 0;
  487. s = s || 0;
  488. ms = ms || 0;
  489. // Special handling for year < 100
  490. var dt = new Date(y < 100 ? 100 : y, m - 1, d, h, i, s, ms).add(Date.YEAR, y < 100 ? y - 100 : 0);
  491. return y == dt.getFullYear() &&
  492. m == dt.getMonth() + 1 &&
  493. d == dt.getDate() &&
  494. h == dt.getHours() &&
  495. i == dt.getMinutes() &&
  496. s == dt.getSeconds() &&
  497. ms == dt.getMilliseconds();
  498. },
  499. <div id="method-Date-parseDate"></div>/**
  500. * Parses the passed string using the specified date format.
  501. * Note that this function expects normal calendar dates, meaning that months are 1-based (i.e. 1 = January).
  502. * The {@link #defaults} hash will be used for any date value (i.e. year, month, day, hour, minute, second or millisecond)
  503. * which cannot be found in the passed string. If a corresponding default date value has not been specified in the {@link #defaults} hash,
  504. * the current date's year, month, day or DST-adjusted zero-hour time value will be used instead.
  505. * Keep in mind that the input date string must precisely match the specified format string
  506. * in order for the parse operation to be successful (failed parse operations return a null value).
  507. * <p>Example:</p><pre><code>
  508. //dt = Fri May 25 2007 (current date)
  509. var dt = new Date();
  510. //dt = Thu May 25 2006 (today&#39;s month/day in 2006)
  511. dt = Date.parseDate("2006", "Y");
  512. //dt = Sun Jan 15 2006 (all date parts specified)
  513. dt = Date.parseDate("2006-01-15", "Y-m-d");
  514. //dt = Sun Jan 15 2006 15:20:01
  515. dt = Date.parseDate("2006-01-15 3:20:01 PM", "Y-m-d g:i:s A");
  516. // attempt to parse Sun Feb 29 2006 03:20:01 in strict mode
  517. dt = Date.parseDate("2006-02-29 03:20:01", "Y-m-d H:i:s", true); // returns null
  518. </code></pre>
  519. * @param {String} input The raw date string.
  520. * @param {String} format The expected date string format.
  521. * @param {Boolean} strict (optional) True to validate date strings while parsing (i.e. prevents javascript Date "rollover")
  522. (defaults to false). Invalid date strings will return null when parsed.
  523. * @return {Date} The parsed Date.
  524. * @static
  525. */
  526. parseDate : function(input, format, strict) {
  527. var p = Date.parseFunctions;
  528. if (p[format] == null) {
  529. Date.createParser(format);
  530. }
  531. return p[format](input, Ext.isDefined(strict) ? strict : Date.useStrict);
  532. },
  533. // private
  534. getFormatCode : function(character) {
  535. var f = Date.formatCodes[character];
  536. if (f) {
  537. f = typeof f == 'function'? f() : f;
  538. Date.formatCodes[character] = f; // reassign function result to prevent repeated execution
  539. }
  540. // note: unknown characters are treated as literals
  541. return f || ("'" + String.escape(character) + "'");
  542. },
  543. // private
  544. createFormat : function(format) {
  545. var code = [],
  546. special = false,
  547. ch = '';
  548. for (var i = 0; i < format.length; ++i) {
  549. ch = format.charAt(i);
  550. if (!special && ch == "\\") {
  551. special = true;
  552. } else if (special) {
  553. special = false;
  554. code.push("'" + String.escape(ch) + "'");
  555. } else {
  556. code.push(Date.getFormatCode(ch));
  557. }
  558. }
  559. Date.formatFunctions[format] = new Function("return " + code.join('+'));
  560. },
  561. // private
  562. createParser : function() {
  563. var code = [
  564. "var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,",
  565. "def = Date.defaults,",
  566. "results = String(input).match(Date.parseRegexes[{0}]);", // either null, or an array of matched strings
  567. "if(results){",
  568. "{1}",
  569. "if(u != null){", // i.e. unix time is defined
  570. "v = new Date(u * 1000);", // give top priority to UNIX time
  571. "}else{",
  572. // create Date object representing midnight of the current day;
  573. // this will provide us with our date defaults
  574. // (note: clearTime() handles Daylight Saving Time automatically)
  575. "dt = (new Date()).clearTime();",
  576. // date calculations (note: these calculations create a dependency on Ext.num())
  577. "y = Ext.num(y, Ext.num(def.y, dt.getFullYear()));",
  578. "m = Ext.num(m, Ext.num(def.m - 1, dt.getMonth()));",
  579. "d = Ext.num(d, Ext.num(def.d, dt.getDate()));",
  580. // time calculations (note: these calculations create a dependency on Ext.num())
  581. "h = Ext.num(h, Ext.num(def.h, dt.getHours()));",
  582. "i = Ext.num(i, Ext.num(def.i, dt.getMinutes()));",
  583. "s = Ext.num(s, Ext.num(def.s, dt.getSeconds()));",
  584. "ms = Ext.num(ms, Ext.num(def.ms, dt.getMilliseconds()));",
  585. "if(z >= 0 && y >= 0){",
  586. // both the year and zero-based day of year are defined and >= 0.
  587. // these 2 values alone provide sufficient info to create a full date object
  588. // create Date object representing January 1st for the given year
  589. // handle years < 100 appropriately
  590. "v = new Date(y < 100 ? 100 : y, 0, 1, h, i, s, ms).add(Date.YEAR, y < 100 ? y - 100 : 0);",
  591. // then add day of year, checking for Date "rollover" if necessary
  592. "v = !strict? v : (strict === true && (z <= 364 || (v.isLeapYear() && z <= 365))? v.add(Date.DAY, z) : null);",
  593. "}else if(strict === true && !Date.isValid(y, m + 1, d, h, i, s, ms)){", // check for Date "rollover"
  594. "v = null;", // invalid date, so return null
  595. "}else{",
  596. // plain old Date object
  597. // handle years < 100 properly
  598. "v = new Date(y < 100 ? 100 : y, m, d, h, i, s, ms).add(Date.YEAR, y < 100 ? y - 100 : 0);",
  599. "}",
  600. "}",
  601. "}",
  602. "if(v){",
  603. // favour UTC offset over GMT offset
  604. "if(zz != null){",
  605. // reset to UTC, then add offset
  606. "v = v.add(Date.SECOND, -v.getTimezoneOffset() * 60 - zz);",
  607. "}else if(o){",
  608. // reset to GMT, then add offset
  609. "v = v.add(Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn));",
  610. "}",
  611. "}",
  612. "return v;"
  613. ].join('\n');
  614. return function(format) {
  615. var regexNum = Date.parseRegexes.length,
  616. currentGroup = 1,
  617. calc = [],
  618. regex = [],
  619. special = false,
  620. ch = "",
  621. i = 0,
  622. obj,
  623. last;
  624. for (; i < format.length; ++i) {
  625. ch = format.charAt(i);
  626. if (!special && ch == "\\") {
  627. special = true;
  628. } else if (special) {
  629. special = false;
  630. regex.push(String.escape(ch));
  631. } else {
  632. obj = $f(ch, currentGroup);
  633. currentGroup += obj.g;
  634. regex.push(obj.s);
  635. if (obj.g && obj.c) {
  636. if (obj.calcLast) {
  637. last = obj.c;
  638. } else {
  639. calc.push(obj.c);
  640. }
  641. }
  642. }
  643. }
  644. if (last) {
  645. calc.push(last);
  646. }
  647. Date.parseRegexes[regexNum] = new RegExp("^" + regex.join('') + "$", 'i');
  648. Date.parseFunctions[format] = new Function("input", "strict", xf(code, regexNum, calc.join('')));
  649. };
  650. }(),
  651. // private
  652. parseCodes : {
  653. /*
  654. * Notes:
  655. * g = {Number} calculation group (0 or 1. only group 1 contributes to date calculations.)
  656. * c = {String} calculation method (required for group 1. null for group 0. {0} = currentGroup - position in regex result array)
  657. * s = {String} regex pattern. all matches are stored in results[], and are accessible by the calculation mapped to 'c'
  658. */
  659. d: {
  660. g:1,
  661. c:"d = parseInt(results[{0}], 10);\n",
  662. s:"(\\d{2})" // day of month with leading zeroes (01 - 31)
  663. },
  664. j: {
  665. g:1,
  666. c:"d = parseInt(results[{0}], 10);\n",
  667. s:"(\\d{1,2})" // day of month without leading zeroes (1 - 31)
  668. },
  669. D: function() {
  670. for (var a = [], i = 0; i < 7; a.push(Date.getShortDayName(i)), ++i); // get localised short day names
  671. return {
  672. g:0,
  673. c:null,
  674. s:"(?:" + a.join("|") +")"
  675. };
  676. },
  677. l: function() {
  678. return {
  679. g:0,
  680. c:null,
  681. s:"(?:" + Date.dayNames.join("|") + ")"
  682. };
  683. },
  684. N: {
  685. g:0,
  686. c:null,
  687. s:"[1-7]" // ISO-8601 day number (1 (monday) - 7 (sunday))
  688. },
  689. S: {
  690. g:0,
  691. c:null,
  692. s:"(?:st|nd|rd|th)"
  693. },
  694. w: {
  695. g:0,
  696. c:null,
  697. s:"[0-6]" // javascript day number (0 (sunday) - 6 (saturday))
  698. },
  699. z: {
  700. g:1,
  701. c:"z = parseInt(results[{0}], 10);\n",
  702. s:"(\\d{1,3})" // day of the year (0 - 364 (365 in leap years))
  703. },
  704. W: {
  705. g:0,
  706. c:null,
  707. s:"(?:\\d{2})" // ISO-8601 week number (with leading zero)
  708. },
  709. F: function() {
  710. return {
  711. g:1,
  712. c:"m = parseInt(Date.getMonthNumber(results[{0}]), 10);\n", // get localised month number
  713. s:"(" + Date.monthNames.join("|") + ")"
  714. };
  715. },
  716. M: function() {
  717. for (var a = [], i = 0; i < 12; a.push(Date.getShortMonthName(i)), ++i); // get localised short month names
  718. return Ext.applyIf({
  719. s:"(" + a.join("|") + ")"
  720. }, $f("F"));
  721. },
  722. m: {
  723. g:1,
  724. c:"m = parseInt(results[{0}], 10) - 1;\n",
  725. s:"(\\d{2})" // month number with leading zeros (01 - 12)
  726. },
  727. n: {
  728. g:1,
  729. c:"m = parseInt(results[{0}], 10) - 1;\n",
  730. s:"(\\d{1,2})" // month number without leading zeros (1 - 12)
  731. },
  732. t: {
  733. g:0,
  734. c:null,
  735. s:"(?:\\d{2})" // no. of days in the month (28 - 31)
  736. },
  737. L: {
  738. g:0,
  739. c:null,
  740. s:"(?:1|0)"
  741. },
  742. o: function() {
  743. return $f("Y");
  744. },
  745. Y: {
  746. g:1,
  747. c:"y = parseInt(results[{0}], 10);\n",
  748. s:"(\\d{4})" // 4-digit year
  749. },
  750. y: {
  751. g:1,
  752. c:"var ty = parseInt(results[{0}], 10);\n"
  753. + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n", // 2-digit year
  754. s:"(\\d{1,2})"
  755. },
  756. <div id="method-Date-a"></div>/**
  757. * In the am/pm parsing routines, we allow both upper and lower case
  758. * even though it doesn't exactly match the spec. It gives much more flexibility
  759. * in being able to specify case insensitive regexes.
  760. */
  761. a: function(){
  762. return $f("A");
  763. },
  764. A: {
  765. // We need to calculate the hour before we apply AM/PM when parsing
  766. calcLast: true,
  767. g:1,
  768. c:"if (/(am)/i.test(results[{0}])) {\n"
  769. + "if (!h || h == 12) { h = 0; }\n"
  770. + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
  771. s:"(AM|PM|am|pm)"
  772. },
  773. g: function() {
  774. return $f("G");
  775. },
  776. G: {
  777. g:1,
  778. c:"h = parseInt(results[{0}], 10);\n",
  779. s:"(\\d{1,2})" // 24-hr format of an hour without leading zeroes (0 - 23)
  780. },
  781. h: function() {
  782. return $f("H");
  783. },
  784. H: {
  785. g:1,
  786. c:"h = parseInt(results[{0}], 10);\n",
  787. s:"(\\d{2})" // 24-hr format of an hour with leading zeroes (00 - 23)
  788. },
  789. i: {
  790. g:1,
  791. c:"i = parseInt(results[{0}], 10);\n",
  792. s:"(\\d{2})" // minutes with leading zeros (00 - 59)
  793. },
  794. s: {
  795. g:1,
  796. c:"s = parseInt(results[{0}], 10);\n",
  797. s:"(\\d{2})" // seconds with leading zeros (00 - 59)
  798. },
  799. u: {
  800. g:1,
  801. c:"ms = results[{0}]; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n",
  802. s:"(\\d+)" // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
  803. },
  804. O: {
  805. g:1,
  806. c:[
  807. "o = results[{0}];",
  808. "var sn = o.substring(0,1),", // get + / - sign
  809. "hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
  810. "mn = o.substring(3,5) % 60;", // get minutes
  811. "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + String.leftPad(hr, 2, '0') + String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
  812. ].join("\n"),
  813. s: "([+\-]\\d{4})" // GMT offset in hrs and mins
  814. },
  815. P: {
  816. g:1,
  817. c:[
  818. "o = results[{0}];",
  819. "var sn = o.substring(0,1),", // get + / - sign
  820. "hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
  821. "mn = o.substring(4,6) % 60;", // get minutes
  822. "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + String.leftPad(hr, 2, '0') + String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
  823. ].join("\n"),
  824. s: "([+\-]\\d{2}:\\d{2})" // GMT offset in hrs and mins (with colon separator)
  825. },
  826. T: {
  827. g:0,
  828. c:null,
  829. s:"[A-Z]{1,4}" // timezone abbrev. may be between 1 - 4 chars
  830. },
  831. Z: {
  832. g:1,
  833. c:"zz = results[{0}] * 1;\n" // -43200 <= UTC offset <= 50400
  834. + "zz = (-43200 <= zz && zz <= 50400)? zz : null;\n",
  835. s:"([+\-]?\\d{1,5})" // leading '+' sign is optional for UTC offset
  836. },
  837. c: function() {
  838. var calc = [],
  839. arr = [
  840. $f("Y", 1), // year
  841. $f("m", 2), // month
  842. $f("d", 3), // day
  843. $f("h", 4), // hour
  844. $f("i", 5), // minute
  845. $f("s", 6), // second
  846. {c:"ms = results[7] || '0'; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n"}, // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
  847. {c:[ // allow either "Z" (i.e. UTC) or "-0530" or "+08:00" (i.e. UTC offset) timezone delimiters. assumes local timezone if no timezone is specified
  848. "if(results[8]) {", // timezone specified
  849. "if(results[8] == 'Z'){",
  850. "zz = 0;", // UTC
  851. "}else if (results[8].indexOf(':') > -1){",
  852. $f("P", 8).c, // timezone offset with colon separator
  853. "}else{",
  854. $f("O", 8).c, // timezone offset without colon separator
  855. "}",
  856. "}"
  857. ].join('\n')}
  858. ];
  859. for (var i = 0, l = arr.length; i < l; ++i) {
  860. calc.push(arr[i].c);
  861. }
  862. return {
  863. g:1,
  864. c:calc.join(""),
  865. s:[
  866. arr[0].s, // year (required)
  867. "(?:", "-", arr[1].s, // month (optional)
  868. "(?:", "-", arr[2].s, // day (optional)
  869. "(?:",
  870. "(?:T| )?", // time delimiter -- either a "T" or a single blank space
  871. arr[3].s, ":", arr[4].s, // hour AND minute, delimited by a single colon (optional). MUST be preceded by either a "T" or a single blank space
  872. "(?::", arr[5].s, ")?", // seconds (optional)
  873. "(?:(?:\\.|,)(\\d+))?", // decimal fraction of a second (e.g. ",12345" or ".98765") (optional)
  874. "(Z|(?:[-+]\\d{2}(?::)?\\d{2}))?", // "Z" (UTC) or "-0530" (UTC offset without colon delimiter) or "+08:00" (UTC offset with colon delimiter) (optional)
  875. ")?",
  876. ")?",
  877. ")?"
  878. ].join("")
  879. };
  880. },
  881. U: {
  882. g:1,
  883. c:"u = parseInt(results[{0}], 10);\n",
  884. s:"(-?\\d+)" // leading minus sign indicates seconds before UNIX epoch
  885. }
  886. }
  887. });
  888. }());
  889. Ext.apply(Date.prototype, {
  890. // private
  891. dateFormat : function(format) {
  892. if (Date.formatFunctions[format] == null) {
  893. Date.createFormat(format);
  894. }
  895. return Date.formatFunctions[format].call(this);
  896. },
  897. <div id="method-Date-getTimezone"></div>/**
  898. * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
  899. *
  900. * Note: The date string returned by the javascript Date object's toString() method varies
  901. * between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America).
  902. * For a given date string e.g. "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)",
  903. * getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses
  904. * (which may or may not be present), failing which it proceeds to get the timezone abbreviation
  905. * from the GMT offset portion of the date string.
  906. * @return {String} The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).
  907. */
  908. getTimezone : function() {
  909. // the following list shows the differences between date strings from different browsers on a WinXP SP2 machine from an Asian locale:
  910. //
  911. // Opera : "Thu, 25 Oct 2007 22:53:45 GMT+0800" -- shortest (weirdest) date string of the lot
  912. // Safari : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone (same as FF)
  913. // FF : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone
  914. // IE : "Thu Oct 25 22:54:35 UTC+0800 2007" -- (Asian system setting) look for 3-4 letter timezone abbrev
  915. // IE : "Thu Oct 25 17:06:37 PDT 2007" -- (American system setting) look for 3-4 letter timezone abbrev
  916. //
  917. // this crazy regex attempts to guess the correct timezone abbreviation despite these differences.
  918. // step 1: (?:\((.*)\) -- find timezone in parentheses
  919. // 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
  920. // step 3: remove all non uppercase characters found in step 1 and 2
  921. return this.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, "");
  922. },
  923. <div id="method-Date-getGMTOffset"></div>/**
  924. * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
  925. * @param {Boolean} colon (optional) true to separate the hours and minutes with a colon (defaults to false).
  926. * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600').
  927. */
  928. getGMTOffset : function(colon) {
  929. return (this.getTimezoneOffset() > 0 ? "-" : "+")
  930. + String.leftPad(Math.floor(Math.abs(this.getTimezoneOffset()) / 60), 2, "0")
  931. + (colon ? ":" : "")
  932. + String.leftPad(Math.abs(this.getTimezoneOffset() % 60), 2, "0");
  933. },
  934. <div id="method-Date-getDayOfYear"></div>/**
  935. * Get the numeric day number of the year, adjusted for leap year.
  936. * @return {Number} 0 to 364 (365 in leap years).
  937. */
  938. getDayOfYear: function() {
  939. var num = 0,
  940. d = this.clone(),
  941. m = this.getMonth(),
  942. i;
  943. for (i = 0, d.setDate(1), d.setMonth(0); i < m; d.setMonth(++i)) {
  944. num += d.getDaysInMonth();
  945. }
  946. return num + this.getDate() - 1;
  947. },
  948. <div id="method-Date-getWeekOfYear"></div>/**
  949. * Get the numeric ISO-8601 week number of the year.
  950. * (equivalent to the format specifier 'W', but without a leading zero).
  951. * @return {Number} 1 to 53
  952. */
  953. getWeekOfYear : function() {
  954. // adapted from http://www.merlyn.demon.co.uk/weekcalc.htm
  955. var ms1d = 864e5, // milliseconds in a day
  956. ms7d = 7 * ms1d; // milliseconds in a week
  957. return function() { // return a closure so constants get calculated only once
  958. var DC3 = Date.UTC(this.getFullYear(), this.getMonth(), this.getDate() + 3) / ms1d, // an Absolute Day Number
  959. AWN = Math.floor(DC3 / 7), // an Absolute Week Number
  960. Wyr = new Date(AWN * ms7d).getUTCFullYear();
  961. return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
  962. };
  963. }(),
  964. <div id="method-Date-isLeapYear"></div>/**
  965. * Checks if the current date falls within a leap year.
  966. * @return {Boolean} True if the current date falls within a leap year, false otherwise.
  967. */
  968. isLeapYear : function() {
  969. var year = this.getFullYear();
  970. return !!((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
  971. },
  972. <div id="method-Date-getFirstDayOfMonth"></div>/**
  973. * Get the first day of the current month, adjusted for leap year. The returned value
  974. * is the numeric day index within the week (0-6) which can be used in conjunction with
  975. * the {@link #monthNames} array to retrieve the textual day name.
  976. * Example:
  977. * <pre><code>
  978. var dt = new Date('1/10/2007');
  979. document.write(Date.dayNames[dt.getFirstDayOfMonth()]); //output: 'Monday'
  980. </code></pre>
  981. * @return {Number} The day number (0-6).
  982. */
  983. getFirstDayOfMonth : function() {
  984. var day = (this.getDay() - (this.getDate() - 1)) % 7;
  985. return (day < 0) ? (day + 7) : day;
  986. },
  987. <div id="method-Date-getLastDayOfMonth"></div>/**
  988. * Get the last day of the current month, adjusted for leap year. The returned value
  989. * is the numeric day index within the week (0-6) which can be used in conjunction with
  990. * the {@link #monthNames} array to retrieve the textual day name.
  991. * Example:
  992. * <pre><code>
  993. var dt = new Date('1/10/2007');
  994. document.write(Date.dayNames[dt.getLastDayOfMonth()]); //output: 'Wednesday'
  995. </code></pre>
  996. * @return {Number} The day number (0-6).
  997. */
  998. getLastDayOfMonth : function() {
  999. return this.getLastDateOfMonth().getDay();
  1000. },
  1001. <div id="method-Date-getFirstDateOfMonth"></div>/**
  1002. * Get the date of the first day of the month in which this date resides.
  1003. * @return {Date}
  1004. */
  1005. getFirstDateOfMonth : function() {
  1006. return new Date(this.getFullYear(), this.getMonth(), 1);
  1007. },
  1008. <div id="method-Date-getLastDateOfMonth"></div>/**
  1009. * Get the date of the last day of the month in which this date resides.
  1010. * @return {Date}
  1011. */
  1012. getLastDateOfMonth : function() {
  1013. return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth());
  1014. },
  1015. <div id="method-Date-getDaysInMonth"></div>/**
  1016. * Get the number of days in the current month, adjusted for leap year.
  1017. * @return {Number} The number of days in the month.
  1018. */
  1019. getDaysInMonth: function() {
  1020. var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  1021. return function() { // return a closure for efficiency
  1022. var m = this.getMonth();
  1023. return m == 1 && this.isLeapYear() ? 29 : daysInMonth[m];
  1024. };
  1025. }(),
  1026. <div id="method-Date-getSuffix"></div>/**
  1027. * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
  1028. * @return {String} 'st, 'nd', 'rd' or 'th'.
  1029. */
  1030. getSuffix : function() {
  1031. switch (this.getDate()) {
  1032. case 1:
  1033. case 21:
  1034. case 31:
  1035. return "st";
  1036. case 2:
  1037. case 22:
  1038. return "nd";
  1039. case 3:
  1040. case 23:
  1041. return "rd";
  1042. default:
  1043. return "th";
  1044. }
  1045. },
  1046. <div id="method-Date-clone"></div>/**
  1047. * Creates and returns a new Date instance with the exact same date value as the called instance.
  1048. * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
  1049. * variable will also be changed. When the intention is to create a new variable that will not
  1050. * modify the original instance, you should create a clone.
  1051. *
  1052. * Example of correctly cloning a date:
  1053. * <pre><code>
  1054. //wrong way:
  1055. var orig = new Date('10/1/2006');
  1056. var copy = orig;
  1057. copy.setDate(5);
  1058. document.write(orig); //returns 'Thu Oct 05 2006'!
  1059. //correct way:
  1060. var orig = new Date('10/1/2006');
  1061. var copy = orig.clone();
  1062. copy.setDate(5);
  1063. document.write(orig); //returns 'Thu Oct 01 2006'
  1064. </code></pre>
  1065. * @return {Date} The new Date instance.
  1066. */
  1067. clone : function() {
  1068. return new Date(this.getTime());
  1069. },
  1070. <div id="method-Date-isDST"></div>/**
  1071. * Checks if the current date is affected by Daylight Saving Time (DST).
  1072. * @return {Boolean} True if the current date is affected by DST.
  1073. */
  1074. isDST : function() {
  1075. // adapted from http://extjs.com/forum/showthread.php?p=247172#post247172
  1076. // courtesy of @geoffrey.mcgill
  1077. return new Date(this.getFullYear(), 0, 1).getTimezoneOffset() != this.getTimezoneOffset();
  1078. },
  1079. <div id="method-Date-clearTime"></div>/**
  1080. * Attempts to clear all time information from this Date by setting the time to midnight of the same day,
  1081. * automatically adjusting for Daylight Saving Time (DST) where applicable.
  1082. * (note: DST timezone information for the browser's host operating system is assumed to be up-to-date)
  1083. * @param {Boolean} clone true to create a clone of this date, clear the time and return it (defaults to false).
  1084. * @return {Date} this or the clone.
  1085. */
  1086. clearTime : function(clone) {
  1087. if (clone) {
  1088. return this.clone().clearTime();
  1089. }
  1090. // get current date before clearing time
  1091. var d = this.getDate();
  1092. // clear time
  1093. this.setHours(0);
  1094. this.setMinutes(0);
  1095. this.setSeconds(0);
  1096. this.setMilliseconds(0);
  1097. if (this.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
  1098. // note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the case)
  1099. // refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
  1100. // increment hour until cloned date == current date
  1101. for (var hr = 1, c = this.add(Date.HOUR, hr); c.getDate() != d; hr++, c = this.add(Date.HOUR, hr));
  1102. this.setDate(d);
  1103. this.setHours(c.getHours());
  1104. }
  1105. return this;
  1106. },
  1107. <div id="method-Date-add"></div>/**
  1108. * Provides a convenient method for performing basic date arithmetic. This method
  1109. * does not modify the Date instance being called - it creates and returns
  1110. * a new Date instance containing the resulting date value.
  1111. *
  1112. * Examples:
  1113. * <pre><code>
  1114. // Basic usage:
  1115. var dt = new Date('10/29/2006').add(Date.DAY, 5);
  1116. document.write(dt); //returns 'Fri Nov 03 2006 00:00:00'
  1117. // Negative values will be subtracted:
  1118. var dt2 = new Date('10/1/2006').add(Date.DAY, -5);
  1119. document.write(dt2); //returns 'Tue Sep 26 2006 00:00:00'
  1120. // You can even chain several calls together in one line:
  1121. var dt3 = new Date('10/1/2006').add(Date.DAY, 5).add(Date.HOUR, 8).add(Date.MINUTE, -30);
  1122. document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00'
  1123. </code></pre>
  1124. *
  1125. * @param {String} interval A valid date interval enum value.
  1126. * @param {Number} value The amount to add to the current date.
  1127. * @return {Date} The new Date instance.
  1128. */
  1129. add : function(interval, value) {
  1130. var d = this.clone();
  1131. if (!interval || value === 0) return d;
  1132. switch(interval.toLowerCase()) {
  1133. case Date.MILLI:
  1134. d.setMilliseconds(this.getMilliseconds() + value);
  1135. break;
  1136. case Date.SECOND:
  1137. d.setSeconds(this.getSeconds() + value);
  1138. break;
  1139. case Date.MINUTE:
  1140. d.setMinutes(this.getMinutes() + value);
  1141. break;
  1142. case Date.HOUR:
  1143. d.setHours(this.getHours() + value);
  1144. break;
  1145. case Date.DAY:
  1146. d.setDate(this.getDate() + value);
  1147. break;
  1148. case Date.MONTH:
  1149. var day = this.getDate();
  1150. if (day > 28) {
  1151. day = Math.min(day, this.getFirstDateOfMonth().add('mo', value).getLastDateOfMonth().getDate());
  1152. }
  1153. d.setDate(day);
  1154. d.setMonth(this.getMonth() + value);
  1155. break;
  1156. case Date.YEAR:
  1157. d.setFullYear(this.getFullYear() + value);
  1158. break;
  1159. }
  1160. return d;
  1161. },
  1162. <div id="method-Date-between"></div>/**
  1163. * Checks if this date falls on or between the given start and end dates.
  1164. * @param {Date} start Start date
  1165. * @param {Date} end End date
  1166. * @return {Boolean} true if this date falls on or between the given start and end dates.
  1167. */
  1168. between : function(start, end) {
  1169. var t = this.getTime();
  1170. return start.getTime() <= t && t <= end.getTime();
  1171. }
  1172. });
  1173. <div id="method-Date-format"></div>/**
  1174. * Formats a date given the supplied format string.
  1175. * @param {String} format The format string.
  1176. * @return {String} The formatted date.
  1177. * @method format
  1178. */
  1179. Date.prototype.format = Date.prototype.dateFormat;
  1180. // private
  1181. if (Ext.isSafari && (navigator.userAgent.match(/WebKit\/(\d+)/)[1] || NaN) < 420) {
  1182. Ext.apply(Date.prototype, {
  1183. _xMonth : Date.prototype.setMonth,
  1184. _xDate : Date.prototype.setDate,
  1185. // Bug in Safari 1.3, 2.0 (WebKit build < 420)
  1186. // Date.setMonth does not work consistently if iMonth is not 0-11
  1187. setMonth : function(num) {
  1188. if (num <= -1) {
  1189. var n = Math.ceil(-num),
  1190. back_year = Math.ceil(n / 12),
  1191. month = (n % 12) ? 12 - n % 12 : 0;
  1192. this.setFullYear(this.getFullYear() - back_year);
  1193. return this._xMonth(month);
  1194. } else {
  1195. return this._xMonth(num);
  1196. }
  1197. },
  1198. // Bug in setDate() method (resolved in WebKit build 419.3, so to be safe we target Webkit builds < 420)
  1199. // The parameter for Date.setDate() is converted to a signed byte integer in Safari
  1200. // http://brianary.blogspot.com/2006/03/safari-date-bug.html
  1201. setDate : function(d) {
  1202. // use setTime() to workaround setDate() bug
  1203. // subtract current day of month in milliseconds, then add desired day of month in milliseconds
  1204. return this.setTime(this.getTime() - (this.getDate() - d) * 864e5);
  1205. }
  1206. });
  1207. }
  1208. /* Some basic Date tests... (requires Firebug)
  1209. Date.parseDate('', 'c'); // call Date.parseDate() once to force computation of regex string so we can console.log() it
  1210. console.log('Insane Regex for "c" format: %o', Date.parseCodes.c.s); // view the insane regex for the "c" format specifier
  1211. // standard tests
  1212. console.group('Standard Date.parseDate() Tests');
  1213. console.log('Date.parseDate("2009-01-05T11:38:56", "c") = %o', Date.parseDate("2009-01-05T11:38:56", "c")); // assumes browser's timezone setting
  1214. console.log('Date.parseDate("2009-02-04T12:37:55.001000", "c") = %o', Date.parseDate("2009-02-04T12:37:55.001000", "c")); // assumes browser's timezone setting
  1215. console.log('Date.parseDate("2009-03-03T13:36:54,101000Z", "c") = %o', Date.parseDate("2009-03-03T13:36:54,101000Z", "c")); // UTC
  1216. console.log('Date.parseDate("2009-04-02T14:35:53.901000-0530", "c") = %o', Date.parseDate("2009-04-02T14:35:53.901000-0530", "c")); // GMT-0530
  1217. console.log('Date.parseDate("2009-05-01T15:34:52,9876000+08:00", "c") = %o', Date.parseDate("2009-05-01T15:34:52,987600+08:00", "c")); // GMT+08:00
  1218. console.groupEnd();
  1219. // ISO-8601 format as specified in http://www.w3.org/TR/NOTE-datetime
  1220. // -- accepts ALL 6 levels of date-time granularity
  1221. console.group('ISO-8601 Granularity Test (see http://www.w3.org/TR/NOTE-datetime)');
  1222. console.log('Date.parseDate("1997", "c") = %o', Date.parseDate("1997", "c")); // YYYY (e.g. 1997)
  1223. console.log('Date.parseDate("1997-07", "c") = %o', Date.parseDate("1997-07", "c")); // YYYY-MM (e.g. 1997-07)
  1224. console.log('Date.parseDate("1997-07-16", "c") = %o', Date.parseDate("1997-07-16", "c")); // YYYY-MM-DD (e.g. 1997-07-16)
  1225. console.log('Date.parseDate("1997-07-16T19:20+01:00", "c") = %o', Date.parseDate("1997-07-16T19:20+01:00", "c")); // YYYY-MM-DDThh:mmTZD (e.g. 1997-07-16T19:20+01:00)
  1226. console.log('Date.parseDate("1997-07-16T19:20:30+01:00", "c") = %o', Date.parseDate("1997-07-16T19:20:30+01:00", "c")); // YYYY-MM-DDThh:mm:ssTZD (e.g. 1997-07-16T19:20:30+01:00)
  1227. console.log('Date.parseDate("1997-07-16T19:20:30.45+01:00", "c") = %o', Date.parseDate("1997-07-16T19:20:30.45+01:00", "c")); // YYYY-MM-DDThh:mm:ss.sTZD (e.g. 1997-07-16T19:20:30.45+01:00)
  1228. console.log('Date.parseDate("1997-07-16 19:20:30.45+01:00", "c") = %o', Date.parseDate("1997-07-16 19:20:30.45+01:00", "c")); // YYYY-MM-DD hh:mm:ss.sTZD (e.g. 1997-07-16T19:20:30.45+01:00)
  1229. console.log('Date.parseDate("1997-13-16T19:20:30.45+01:00", "c", true)= %o', Date.parseDate("1997-13-16T19:20:30.45+01:00", "c", true)); // strict date parsing with invalid month value
  1230. console.groupEnd();
  1231. */
  1232. </pre>
  1233. </body>
  1234. </html>