123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585 |
- /*
- * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
- *
- * http://extjs.com/license
- */
- Date.parseFunctions = {
- count : 0
- };
- Date.parseRegexes = [];
- Date.formatFunctions = {
- count : 0
- };
- Date.prototype.dateFormat = function(B) {
- if (Date.formatFunctions[B] == null) {
- Date.createNewFormat(B)
- }
- var A = Date.formatFunctions[B];
- return this[A]()
- };
- Date.prototype.format = Date.prototype.dateFormat;
- Date.createNewFormat = function(format) {
- var funcName = "format" + Date.formatFunctions.count++;
- Date.formatFunctions[format] = funcName;
- var code = "Date.prototype." + funcName + " = function(){return ";
- var special = false;
- var ch = "";
- for (var i = 0; i < format.length; ++i) {
- ch = format.charAt(i);
- if (!special && ch == "\\") {
- special = true
- } else {
- if (special) {
- special = false;
- code += "'" + String.escape(ch) + "' + "
- } else {
- code += Date.getFormatCode(ch)
- }
- }
- }
- eval(code.substring(0, code.length - 3) + ";}")
- };
- Date.getFormatCode = function(D) {
- switch (D) {
- case "d" :
- return "String.leftPad(this.getDate(), 2, '0') + ";
- case "D" :
- return "Date.getShortDayName(this.getDay()) + ";
- case "j" :
- return "this.getDate() + ";
- case "l" :
- return "Date.dayNames[this.getDay()] + ";
- case "N" :
- return "(this.getDay() ? this.getDay() : 7) + ";
- case "S" :
- return "this.getSuffix() + ";
- case "w" :
- return "this.getDay() + ";
- case "z" :
- return "this.getDayOfYear() + ";
- case "W" :
- return "String.leftPad(this.getWeekOfYear(), 2, '0') + ";
- case "F" :
- return "Date.monthNames[this.getMonth()] + ";
- case "m" :
- return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
- case "M" :
- return "Date.getShortMonthName(this.getMonth()) + ";
- case "n" :
- return "(this.getMonth() + 1) + ";
- case "t" :
- return "this.getDaysInMonth() + ";
- case "L" :
- return "(this.isLeapYear() ? 1 : 0) + ";
- case "o" :
- return "(this.getFullYear() + (this.getWeekOfYear() == 1 && this.getMonth() > 0 ? +1 : (this.getWeekOfYear() >= 52 && this.getMonth() < 11 ? -1 : 0))) + ";
- case "Y" :
- return "this.getFullYear() + ";
- case "y" :
- return "('' + this.getFullYear()).substring(2, 4) + ";
- case "a" :
- return "(this.getHours() < 12 ? 'am' : 'pm') + ";
- case "A" :
- return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
- case "g" :
- return "((this.getHours() % 12) ? this.getHours() % 12 : 12) + ";
- case "G" :
- return "this.getHours() + ";
- case "h" :
- return "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0') + ";
- case "H" :
- return "String.leftPad(this.getHours(), 2, '0') + ";
- case "i" :
- return "String.leftPad(this.getMinutes(), 2, '0') + ";
- case "s" :
- return "String.leftPad(this.getSeconds(), 2, '0') + ";
- case "u" :
- return "String.leftPad(this.getMilliseconds(), 3, '0') + ";
- case "O" :
- return "this.getGMTOffset() + ";
- case "P" :
- return "this.getGMTOffset(true) + ";
- case "T" :
- return "this.getTimezone() + ";
- case "Z" :
- return "(this.getTimezoneOffset() * -60) + ";
- case "c" :
- for (var F = Date.getFormatCode, G = "Y-m-dTH:i:sP", C = "", B = 0, A = G.length; B < A; ++B) {
- var E = G.charAt(B);
- C += E == "T" ? "'T' + " : F(E)
- }
- return C;
- case "U" :
- return "Math.round(this.getTime() / 1000) + ";
- default :
- return "'" + String.escape(D) + "' + "
- }
- };
- Date.parseDate = function(A, C) {
- if (Date.parseFunctions[C] == null) {
- Date.createParser(C)
- }
- var B = Date.parseFunctions[C];
- return Date[B](A)
- };
- Date.createParser = function(format) {
- var funcName = "parse" + Date.parseFunctions.count++;
- var regexNum = Date.parseRegexes.length;
- var currentGroup = 1;
- Date.parseFunctions[format] = funcName;
- var code = "Date."
- + funcName
- + " = function(input){\n"
- + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1, ms = -1, o, z, u, v;\n"
- + "var d = allGetServerTime();\n" + "y = d.getFullYear();\n"
- + "m = d.getMonth();\n" + "d = d.getDate();\n"
- + "var results = input.match(Date.parseRegexes[" + regexNum
- + "]);\n" + "if (results && results.length > 0) {";
- var regex = "";
- var special = false;
- var ch = "";
- for (var i = 0; i < format.length; ++i) {
- ch = format.charAt(i);
- if (!special && ch == "\\") {
- special = true
- } else {
- if (special) {
- special = false;
- regex += String.escape(ch)
- } else {
- var obj = Date.formatCodeToRegex(ch, currentGroup);
- currentGroup += obj.g;
- regex += obj.s;
- if (obj.g && obj.c) {
- code += obj.c
- }
- }
- }
- }
- code += "if (u)\n"
- + "{v = new Date(u * 1000);}"
- + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0 && ms >= 0)\n"
- + "{v = new Date(y, m, d, h, i, s, ms);}\n"
- + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
- + "{v = new Date(y, m, d, h, i, s);}\n"
- + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
- + "{v = new Date(y, m, d, h, i);}\n"
- + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0)\n"
- + "{v = new Date(y, m, d, h);}\n"
- + "else if (y >= 0 && m >= 0 && d > 0)\n"
- + "{v = new Date(y, m, d);}\n"
- + "else if (y >= 0 && m >= 0)\n"
- + "{v = new Date(y, m);}\n"
- + "else if (y >= 0)\n"
- + "{v = new Date(y);}\n"
- + "}return (v && (z || o))?\n"
- + " (z ? v.add(Date.SECOND, (v.getTimezoneOffset() * 60) + (z*1)) :\n"
- + " v.add(Date.HOUR, (v.getGMTOffset() / 100) + (o / -100))) : v\n"
- + ";}";
- Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$", "i");
- eval(code)
- };
- Date.formatCodeToRegex = function(G, F) {
- switch (G) {
- case "d" :
- return {
- g : 1,
- c : "d = parseInt(results[" + F + "], 10);\n",
- s : "(\\d{2})"
- };
- case "D" :
- for (var C = [], E = 0; E < 7; C.push(Date.getShortDayName(E)), ++E) {
- }
- return {
- g : 0,
- c : null,
- s : "(?:" + C.join("|") + ")"
- };
- case "j" :
- return {
- g : 1,
- c : "d = parseInt(results[" + F + "], 10);\n",
- s : "(\\d{1,2})"
- };
- case "l" :
- return {
- g : 0,
- c : null,
- s : "(?:" + Date.dayNames.join("|") + ")"
- };
- case "N" :
- return {
- g : 0,
- c : null,
- s : "[1-7]"
- };
- case "S" :
- return {
- g : 0,
- c : null,
- s : "(?:st|nd|rd|th)"
- };
- case "w" :
- return {
- g : 0,
- c : null,
- s : "[0-6]"
- };
- case "z" :
- return {
- g : 0,
- c : null,
- s : "(?:\\d{1,3}"
- };
- case "W" :
- return {
- g : 0,
- c : null,
- s : "(?:\\d{2})"
- };
- case "F" :
- return {
- g : 1,
- c : "m = parseInt(Date.getMonthNumber(results[" + F
- + "]), 10);\n",
- s : "(" + Date.monthNames.join("|") + ")"
- };
- case "m" :
- return {
- g : 1,
- c : "m = parseInt(results[" + F + "], 10) - 1;\n",
- s : "(\\d{2})"
- };
- case "M" :
- for (var C = [], E = 0; E < 12; C.push(Date.getShortMonthName(E)), ++E) {
- }
- return {
- g : 1,
- c : "m = parseInt(Date.getMonthNumber(results[" + F
- + "]), 10);\n",
- s : "(" + C.join("|") + ")"
- };
- case "n" :
- return {
- g : 1,
- c : "m = parseInt(results[" + F + "], 10) - 1;\n",
- s : "(\\d{1,2})"
- };
- case "t" :
- return {
- g : 0,
- c : null,
- s : "(?:\\d{2})"
- };
- case "L" :
- return {
- g : 0,
- c : null,
- s : "(?:1|0)"
- };
- case "o" :
- case "Y" :
- return {
- g : 1,
- c : "y = parseInt(results[" + F + "], 10);\n",
- s : "(\\d{4})"
- };
- case "y" :
- return {
- g : 1,
- c : "var ty = parseInt(results[" + F + "], 10);\n"
- + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
- s : "(\\d{1,2})"
- };
- case "a" :
- return {
- g : 1,
- c : "if (results[" + F + "] == 'am') {\n"
- + "if (h == 12) { h = 0; }\n"
- + "} else { if (h < 12) { h += 12; }}",
- s : "(am|pm)"
- };
- case "A" :
- return {
- g : 1,
- c : "if (results[" + F + "] == 'AM') {\n"
- + "if (h == 12) { h = 0; }\n"
- + "} else { if (h < 12) { h += 12; }}",
- s : "(AM|PM)"
- };
- case "g" :
- case "G" :
- return {
- g : 1,
- c : "h = parseInt(results[" + F + "], 10);\n",
- s : "(\\d{1,2})"
- };
- case "h" :
- case "H" :
- return {
- g : 1,
- c : "h = parseInt(results[" + F + "], 10);\n",
- s : "(\\d{2})"
- };
- case "i" :
- return {
- g : 1,
- c : "i = parseInt(results[" + F + "], 10);\n",
- s : "(\\d{2})"
- };
- case "s" :
- return {
- g : 1,
- c : "s = parseInt(results[" + F + "], 10);\n",
- s : "(\\d{2})"
- };
- case "u" :
- return {
- g : 1,
- c : "ms = parseInt(results[" + F + "], 10);\n",
- s : "(\\d{3})"
- };
- case "O" :
- return {
- g : 1,
- c : [
- "o = results[",
- F,
- "];\n",
- "var sn = o.substring(0,1);\n",
- "var hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60);\n",
- "var mn = o.substring(3,5) % 60;\n",
- "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n",
- " (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"]
- .join(""),
- s : "([+-]\\d{4})"
- };
- case "P" :
- return {
- g : 1,
- c : [
- "o = results[",
- F,
- "];\n",
- "var sn = o.substring(0,1);\n",
- "var hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60);\n",
- "var mn = o.substring(4,6) % 60;\n",
- "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n",
- " (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"]
- .join(""),
- s : "([+-]\\d{2}:\\d{2})"
- };
- case "T" :
- return {
- g : 0,
- c : null,
- s : "[A-Z]{1,4}"
- };
- case "Z" :
- return {
- g : 1,
- c : "z = results[" + F + "] * 1;\n"
- + "z = (-43200 <= z && z <= 50400)? z : null;\n",
- s : "([+-]?\\d{1,5})"
- };
- case "c" :
- var H = Date.formatCodeToRegex, D = [];
- var A = [H("Y", 1), H("m", 2), H("d", 3), H("h", 4), H("i", 5),
- H("s", 6), H("P", 7)];
- for (var E = 0, B = A.length; E < B; ++E) {
- D.push(A[E].c)
- }
- return {
- g : 1,
- c : D.join(""),
- s : A[0].s + "-" + A[1].s + "-" + A[2].s + "T" + A[3].s + ":"
- + A[4].s + ":" + A[5].s + A[6].s
- };
- case "U" :
- return {
- g : 1,
- c : "u = parseInt(results[" + F + "], 10);\n",
- s : "(-?\\d+)"
- };
- default :
- return {
- g : 0,
- c : null,
- s : Ext.escapeRe(G)
- }
- }
- };
- Date.prototype.getTimezone = function() {
- return this.toString().replace(
- /^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/,
- "$1$2").replace(/[^A-Z]/g, "")
- };
- Date.prototype.getGMTOffset = function(A) {
- return (this.getTimezoneOffset() > 0 ? "-" : "+")
- + String.leftPad(Math
- .abs(Math.floor(this.getTimezoneOffset() / 60)), 2,
- "0") + (A ? ":" : "")
- + String.leftPad(this.getTimezoneOffset() % 60, 2, "0")
- };
- Date.prototype.getDayOfYear = function() {
- var A = 0;
- Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
- for (var B = 0; B < this.getMonth(); ++B) {
- A += Date.daysInMonth[B]
- }
- return A + this.getDate() - 1
- };
- Date.prototype.getWeekOfYear = function() {
- var B = 86400000;
- var C = 7 * B;
- var D = Date.UTC(this.getFullYear(), this.getMonth(), this.getDate() + 3)
- / B;
- var A = Math.floor(D / 7);
- var E = new Date(A * C).getUTCFullYear();
- return A - Math.floor(Date.UTC(E, 0, 7) / C) + 1
- };
- Date.prototype.isLeapYear = function() {
- var A = this.getFullYear();
- return ((A & 3) == 0 && (A % 100 || (A % 400 == 0 && A)))
- };
- Date.prototype.getFirstDayOfMonth = function() {
- var A = (this.getDay() - (this.getDate() - 1)) % 7;
- return (A < 0) ? (A + 7) : A
- };
- Date.prototype.getLastDayOfMonth = function() {
- var A = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this
- .getDate()))
- % 7;
- return (A < 0) ? (A + 7) : A
- };
- Date.prototype.getFirstDateOfMonth = function() {
- return new Date(this.getFullYear(), this.getMonth(), 1)
- };
- Date.prototype.getLastDateOfMonth = function() {
- return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth())
- };
- Date.prototype.getDaysInMonth = function() {
- Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
- return Date.daysInMonth[this.getMonth()]
- };
- Date.prototype.getSuffix = function() {
- switch (this.getDate()) {
- case 1 :
- case 21 :
- case 31 :
- return "st";
- case 2 :
- case 22 :
- return "nd";
- case 3 :
- case 23 :
- return "rd";
- default :
- return "th"
- }
- };
- Date.daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
- Date.monthNames = ["January", "February", "March", "April", "May", "June",
- "July", "August", "September", "October", "November", "December"];
- Date.getShortMonthName = function(A) {
- return Date.monthNames[A].substring(0, 3)
- };
- Date.dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
- "Friday", "Saturday"];
- Date.getShortDayName = function(A) {
- return Date.dayNames[A].substring(0, 3)
- };
- Date.y2kYear = 50;
- Date.monthNumbers = {
- Jan : 0,
- Feb : 1,
- Mar : 2,
- Apr : 3,
- May : 4,
- Jun : 5,
- Jul : 6,
- Aug : 7,
- Sep : 8,
- Oct : 9,
- Nov : 10,
- Dec : 11
- };
- Date.getMonthNumber = function(A) {
- return Date.monthNumbers[A.substring(0, 1).toUpperCase()
- + A.substring(1, 3).toLowerCase()]
- };
- Date.prototype.clone = function() {
- return new Date(this.getTime())
- };
- Date.prototype.clearTime = function(A) {
- if (A) {
- return this.clone().clearTime()
- }
- this.setHours(0);
- this.setMinutes(0);
- this.setSeconds(0);
- this.setMilliseconds(0);
- return this
- };
- if (Ext.isSafari) {
- Date.brokenSetMonth = Date.prototype.setMonth;
- Date.prototype.setMonth = function(A) {
- if (A <= -1) {
- var D = Math.ceil(-A);
- var C = Math.ceil(D / 12);
- var B = (D % 12) ? 12 - D % 12 : 0;
- this.setFullYear(this.getFullYear() - C);
- return Date.brokenSetMonth.call(this, B)
- } else {
- return Date.brokenSetMonth.apply(this, arguments)
- }
- }
- }
- Date.MILLI = "ms";
- Date.SECOND = "s";
- Date.MINUTE = "mi";
- Date.HOUR = "h";
- Date.DAY = "d";
- Date.MONTH = "mo";
- Date.YEAR = "y";
- Date.prototype.add = function(B, C) {
- var D = this.clone();
- if (!B || C === 0) {
- return D
- }
- switch (B.toLowerCase()) {
- case Date.MILLI :
- D.setMilliseconds(this.getMilliseconds() + C);
- break;
- case Date.SECOND :
- D.setSeconds(this.getSeconds() + C);
- break;
- case Date.MINUTE :
- D.setMinutes(this.getMinutes() + C);
- break;
- case Date.HOUR :
- D.setHours(this.getHours() + C);
- break;
- case Date.DAY :
- D.setDate(this.getDate() + C);
- break;
- case Date.MONTH :
- var A = this.getDate();
- if (A > 28) {
- A = Math.min(A, this.getFirstDateOfMonth().add("mo", C)
- .getLastDateOfMonth().getDate())
- }
- D.setDate(A);
- D.setMonth(this.getMonth() + C);
- break;
- case Date.YEAR :
- D.setFullYear(this.getFullYear() + C);
- break
- }
- return D
- };
- Date.prototype.between = function(C, A) {
- var B = this.getTime();
- return C.getTime() <= B && B <= A.getTime()
- };
|