Getting consistent datestring parsing in Chrome and Firefox. r=crschmidt (closes #2994)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11281 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2011-02-23 09:32:36 +00:00
parent abb2bb509d
commit 75538b6f42
+5 -9
View File
@@ -632,9 +632,11 @@ OpenLayers.Date = {
* APIMethod: parse * APIMethod: parse
* Generate a date object from a string. The format for the string follows * Generate a date object from a string. The format for the string follows
* the profile of ISO 8601 for date and time on the Internet (see * the profile of ISO 8601 for date and time on the Internet (see
* http://tools.ietf.org/html/rfc3339). If the parse method on * http://tools.ietf.org/html/rfc3339). We don't call the native
* the Date constructor returns a valid date for the given string, * Date.parse because of inconsistency between implmentations. In
* that method is used. * Chrome, calling Date.parse with a string that doesn't contain any
* indication of the timezone (e.g. "2011"), the date is interpreted
* in local time. On Firefox, the assumption is UTC.
* *
* Parameters: * Parameters:
* str - {String} A string representing the date (e.g. * str - {String} A string representing the date (e.g.
@@ -647,11 +649,6 @@ OpenLayers.Date = {
*/ */
parse: function(str) { parse: function(str) {
var date; var date;
// first check if the native parse method can parse it
var elapsed = Date.parse(str);
if (!isNaN(elapsed)) {
date = new Date(elapsed);
} else {
var match = str.match(/^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))?$/); var match = str.match(/^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))?$/);
if (match && (match[1] || match[7])) { // must have at least year or time if (match && (match[1] || match[7])) { // must have at least year or time
var year = parseInt(match[1], 10) || 0; var year = parseInt(match[1], 10) || 0;
@@ -678,7 +675,6 @@ OpenLayers.Date = {
} else { } else {
date = new Date("invalid"); date = new Date("invalid");
} }
}
return date; return date;
} }