X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Date.js;h=fffb3b71d1840e9f5ae39fc2627dfe7fa91b810d;hb=2dd06c4c3e0f351d16332bd7a5fba608af1219ca;hp=88904904f48d6943ebd0818f3778fbe569c42cd4;hpb=44252968cc5a2fcec5e41ca13ad33b567142b6f0;p=roojs1 diff --git a/Date.js b/Date.js index 88904904f4..fffb3b71d1 100644 --- a/Date.js +++ b/Date.js @@ -47,7 +47,7 @@ Format Output Description H 15 24-hour format of an hour with leading zeros i 05 Minutes with leading zeros s 01 Seconds, with leading zeros - O -0600 Difference to Greenwich time (GMT) in hours + O -0600 Difference to Greenwich time (GMT) in hours (Allows +08, without minutes) P -06:00 Difference to Greenwich time (GMT) with colon between hours and minutes T CST Timezone setting of the machine running the code Z -21600 Timezone offset in seconds (negative if west of UTC, positive if east) @@ -261,6 +261,7 @@ Date.parseDate = function(input, format) { /** * @private */ + Date.createParser = function(format) { var funcName = "parse" + Date.parseFunctions.count++; var regexNum = Date.parseRegexes.length; @@ -273,6 +274,7 @@ Date.createParser = function(format) { + "y = d.getFullYear();\n" + "m = d.getMonth();\n" + "d = d.getDate();\n" + + "if (typeof(input) !== 'string') { input = input.toString(); }\n" + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n" + "if (results && results.length > 0) {"; var regex = ""; @@ -299,17 +301,17 @@ Date.createParser = function(format) { } code += "if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n" - + "{v = new Date(y, m, d, h, i, s);}\n" + + "{v = new Date(y, m, d, h, i, s); v.setFullYear(y);}\n" + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n" - + "{v = new Date(y, m, d, h, i);}\n" + + "{v = new Date(y, m, d, h, i); v.setFullYear(y);}\n" + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0)\n" - + "{v = new Date(y, m, d, h);}\n" + + "{v = new Date(y, m, d, h); v.setFullYear(y);}\n" + "else if (y >= 0 && m >= 0 && d > 0)\n" - + "{v = new Date(y, m, d);}\n" + + "{v = new Date(y, m, d); v.setFullYear(y);}\n" + "else if (y >= 0 && m >= 0)\n" - + "{v = new Date(y, m);}\n" + + "{v = new Date(y, m); v.setFullYear(y);}\n" + "else if (y >= 0)\n" - + "{v = new Date(y);}\n" + + "{v = new Date(y); v.setFullYear(y);}\n" + "}return (v && (z || o))?\n" // favour UTC offset over GMT offset + " ((z)? v.add(Date.SECOND, (v.getTimezoneOffset() * 60) + (z*1)) :\n" // reset to UTC, then add offset + " v.add(Date.HOUR, (v.getGMTOffset() / 100) + (o / -100))) : v\n" // reset to GMT, then add offset @@ -369,7 +371,7 @@ Date.formatCodeToRegex = function(character, currentGroup) { s:"(\\d{1,2})"}; // Numeric representation of a month, without leading zeros case "m": return {g:1, - c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n", + c:"m = Math.max(0,parseInt(results[" + currentGroup + "], 10) - 1);\n", s:"(\\d{2})"}; // Numeric representation of a month, with leading zeros case "t": return {g:0, @@ -428,7 +430,9 @@ Date.formatCodeToRegex = function(character, currentGroup) { "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n", // -12hrs <= GMT offset <= 14hrs " (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n" ].join(""), - s:"([+\-]\\d{4})"}; + s:"([+\-]\\d{2,4})"}; + + case "P": return {g:1, c:[ @@ -700,8 +704,8 @@ Date.prototype.clearTime = function(clone){ }; // private -// safari setMonth is broken -if(Roo.isSafari){ +// safari setMonth is broken -- check that this is only donw once... +if(Roo.isSafari && typeof(Date.brokenSetMonth) == 'undefined'){ Date.brokenSetMonth = Date.prototype.setMonth; Date.prototype.setMonth = function(num){ if(num <= -1){ @@ -771,7 +775,7 @@ document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00' */ Date.prototype.add = function(interval, value){ var d = this.clone(); - if (!interval || value === 0) return d; + if (!interval || value === 0) { return d; } switch(interval.toLowerCase()){ case Date.MILLI: d.setMilliseconds(this.getMilliseconds() + value);