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:
@@ -632,9 +632,11 @@ OpenLayers.Date = {
|
||||
* APIMethod: parse
|
||||
* 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
|
||||
* http://tools.ietf.org/html/rfc3339). If the parse method on
|
||||
* the Date constructor returns a valid date for the given string,
|
||||
* that method is used.
|
||||
* http://tools.ietf.org/html/rfc3339). We don't call the native
|
||||
* Date.parse because of inconsistency between implmentations. In
|
||||
* 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:
|
||||
* str - {String} A string representing the date (e.g.
|
||||
@@ -647,11 +649,6 @@ OpenLayers.Date = {
|
||||
*/
|
||||
parse: function(str) {
|
||||
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}))?)))?$/);
|
||||
if (match && (match[1] || match[7])) { // must have at least year or time
|
||||
var year = parseInt(match[1], 10) || 0;
|
||||
@@ -678,7 +675,6 @@ OpenLayers.Date = {
|
||||
} else {
|
||||
date = new Date("invalid");
|
||||
}
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user