Merge pull request #9 from tschaub/date

Making date parsing a bit more lenient (r=ahocevar closes #3542).
This commit is contained in:
Tim Schaub
2011-10-07 08:29:13 -07:00
2 changed files with 14 additions and 2 deletions

View File

@@ -87,7 +87,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}))?)))?$/);
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(93);
t.plan(114);
var cases = {
"2000": {
@@ -127,6 +127,18 @@
minutes: 51,
seconds: 25,
milliseconds: 123
},
"2000Z": { // lenient (Chrome accepts this)
year: 2000
},
"2000-02Z": { // lenient (Chrome accepts this)
year: 2000,
month: 1
},
"2000-04-15Z": { // lenient (Chrome accepts this)
year: 2000,
month: 3,
date: 15
}
};