X-Git-Url: http://git.roojs.org/?p=roojs1;a=blobdiff_plain;f=Date.js;h=6f217a5d556ced3d05d021801a88a20197a4ab75;hp=d9d61aed2ea1f2f1c3ccf29fda8b373ccd59f509;hb=refs%2Fheads%2Fwip_alan_T5944_trim_leading_white_space_from;hpb=b0325bfdb3dd5387340b6e834ee6bcdc742891d6 diff --git a/Date.js b/Date.js index d9d61aed2e..6f217a5d55 100644 --- a/Date.js +++ b/Date.js @@ -47,7 +47,8 @@ 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) @@ -214,6 +215,8 @@ Date.getFormatCode = function(character) { return "String.leftPad(this.getSeconds(), 2, '0') + "; case "O": return "this.getGMTOffset() + "; + case "P": + return "this.getGMTColonOffset() + "; case "T": return "this.getTimezone() + "; case "Z": @@ -258,6 +261,7 @@ Date.parseDate = function(input, format) { /** * @private */ + Date.createParser = function(format) { var funcName = "parse" + Date.parseFunctions.count++; var regexNum = Date.parseRegexes.length; @@ -270,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 = ""; @@ -313,7 +318,7 @@ Date.createParser = function(format) { + ";}"; Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$"); - /* eval:var:zzzzzzzzzzzzz */ + /** eval:var:zzzzzzzzzzzzz */ eval(code); }; @@ -425,6 +430,19 @@ 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{2,4})"}; + + + case "P": + return {g:1, + c:[ + "o = results[", currentGroup, "];\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{4})"}; case "T": return {g:0, @@ -460,6 +478,18 @@ Date.prototype.getGMTOffset = function() { + String.leftPad(this.getTimezoneOffset() % 60, 2, "0"); }; +/** + * Get the offset from GMT of the current date (equivalent to the format specifier 'P'). + * @return {String} 2-characters representing hours and 2-characters representing minutes + * seperated by a colon and prefixed with + or - (e.g. '-06:00') + */ +Date.prototype.getGMTColonOffset = function() { + return (this.getTimezoneOffset() > 0 ? "-" : "+") + + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0") + + ":" + + String.leftPad(this.getTimezoneOffset() %60, 2, "0"); +} + /** * Get the numeric day number of the year, adjusted for leap year. * @return {Number} 0 through 364 (365 in leap years) @@ -674,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){ @@ -745,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); @@ -775,4 +805,4 @@ Date.prototype.add = function(interval, value){ break; } return d; -}; \ No newline at end of file +};