From 90a8ac9c71dac42197134ca2ae9d8838723c025b Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 17 Apr 2012 14:23:56 +0200 Subject: [PATCH] allow for negative years in dates --- lib/OpenLayers/BaseTypes/Date.js | 2 +- tests/BaseTypes/Date.html | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/BaseTypes/Date.js b/lib/OpenLayers/BaseTypes/Date.js index f42b713e12..7e721fed0c 100644 --- a/lib/OpenLayers/BaseTypes/Date.js +++ b/lib/OpenLayers/BaseTypes/Date.js @@ -91,7 +91,7 @@ OpenLayers.Date = { */ parse: function(str) { var date; - 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}))?)))|Z)?$/); + 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}))?)))|Z)?$/); if (match && (match[1] || match[7])) { // must have at least year or time var year = parseInt(match[1], 10) || 0; var month = (parseInt(match[2], 10) - 1) || 0; diff --git a/tests/BaseTypes/Date.html b/tests/BaseTypes/Date.html index a433d84f24..af12348772 100644 --- a/tests/BaseTypes/Date.html +++ b/tests/BaseTypes/Date.html @@ -35,7 +35,7 @@ function test_Date_parse(t) { - t.plan(114); + t.plan(121); var cases = { "2000": { @@ -139,6 +139,11 @@ year: 2000, month: 3, date: 15 + }, + "-0501-03-01T00:00:00.000Z": { + year: -501, + month: 2, + date: 1 } };