allow for negative years in dates

This commit is contained in:
Bart van den Eijnden
2012-04-17 14:23:56 +02:00
parent b683c9bae1
commit 90a8ac9c71
2 changed files with 7 additions and 2 deletions

View File

@@ -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;

View File

@@ -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
}
};