From: Iskren Chernev Date: Fri, 22 Nov 2013 00:02:26 +0000 (-0800) Subject: Handle iso format where Z is prefixed with spaces X-Git-Tag: 2.5.0^2~32^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac041d308ae3b1fc8d5eaff1664d102110ab5181;p=thirdparty%2Fmoment.git Handle iso format where Z is prefixed with spaces In response to #1290 --- diff --git a/moment.js b/moment.js index e445d7b1d..f343687e0 100644 --- a/moment.js +++ b/moment.js @@ -56,7 +56,7 @@ // preliminary iso regex // 0000-00-00 0000-W00 or 0000-W00-0 + T + 00 or 00:00 or 00:00:00 or 00:00:00.000 + +00:00 or +0000) - isoRegex = /^\s*\d{4}-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d:?\d\d|Z)?)?$/, + isoRegex = /^\s*\d{4}-(?:(\d\d-\d\d)|(W\d\d$)|(W\d\d-\d)|(\d\d\d))((T| )(\d\d(:\d\d(:\d\d(\.\d+)?)?)?)?([\+\-]\d\d:?\d\d|\s*Z)?)?$/, isoFormat = 'YYYY-MM-DDTHH:mm:ssZ', diff --git a/test/moment/create.js b/test/moment/create.js index 86d6dd79f..54afea0b4 100644 --- a/test/moment/create.js +++ b/test/moment/create.js @@ -500,29 +500,32 @@ exports.create = { "parsing ISO with Z" : function (test) { var i, mom, formats = [ - ['2011-10-08T18:04Z', '2011-10-08T18:04:00.000'], - ['2011-10-08T18:04:20Z', '2011-10-08T18:04:20.000'], - ['2011-10-08T18:04:20.1Z', '2011-10-08T18:04:20.100'], - ['2011-10-08T18:04:20.11Z', '2011-10-08T18:04:20.110'], - ['2011-10-08T18:04:20.111Z', '2011-10-08T18:04:20.111'], - ['2011-W40-6T18Z', '2011-10-08T18:00:00.000'], - ['2011-W40-6T18:04Z', '2011-10-08T18:04:00.000'], - ['2011-W40-6T18:04:20Z', '2011-10-08T18:04:20.000'], - ['2011-W40-6T18:04:20.1Z', '2011-10-08T18:04:20.100'], - ['2011-W40-6T18:04:20.11Z', '2011-10-08T18:04:20.110'], - ['2011-W40-6T18:04:20.111Z', '2011-10-08T18:04:20.111'], - ['2011-281T18Z', '2011-10-08T18:00:00.000'], - ['2011-281T18:04Z', '2011-10-08T18:04:00.000'], - ['2011-281T18:04:20Z', '2011-10-08T18:04:20.000'], - ['2011-281T18:04:20Z', '2011-10-08T18:04:20.000'], - ['2011-281T18:04:20.1Z', '2011-10-08T18:04:20.100'], - ['2011-281T18:04:20.11Z', '2011-10-08T18:04:20.110'], - ['2011-281T18:04:20.111Z', '2011-10-08T18:04:20.111'] + ['2011-10-08T18:04', '2011-10-08T18:04:00.000'], + ['2011-10-08T18:04:20', '2011-10-08T18:04:20.000'], + ['2011-10-08T18:04:20.1', '2011-10-08T18:04:20.100'], + ['2011-10-08T18:04:20.11', '2011-10-08T18:04:20.110'], + ['2011-10-08T18:04:20.111', '2011-10-08T18:04:20.111'], + ['2011-W40-6T18', '2011-10-08T18:00:00.000'], + ['2011-W40-6T18:04', '2011-10-08T18:04:00.000'], + ['2011-W40-6T18:04:20', '2011-10-08T18:04:20.000'], + ['2011-W40-6T18:04:20.1', '2011-10-08T18:04:20.100'], + ['2011-W40-6T18:04:20.11', '2011-10-08T18:04:20.110'], + ['2011-W40-6T18:04:20.111', '2011-10-08T18:04:20.111'], + ['2011-281T18', '2011-10-08T18:00:00.000'], + ['2011-281T18:04', '2011-10-08T18:04:00.000'], + ['2011-281T18:04:20', '2011-10-08T18:04:20.000'], + ['2011-281T18:04:20', '2011-10-08T18:04:20.000'], + ['2011-281T18:04:20.1', '2011-10-08T18:04:20.100'], + ['2011-281T18:04:20.11', '2011-10-08T18:04:20.110'], + ['2011-281T18:04:20.111', '2011-10-08T18:04:20.111'] ]; for (i = 0; i < formats.length; i++) { - mom = moment(formats[i][0]).utc(); - test.equal(mom.format('YYYY-MM-DDTHH:mm:ss.SSS'), formats[i][1], "moment should be able to parse ISO in UTC " + formats[i][0]); + mom = moment(formats[i][0] + 'Z').utc(); + test.equal(mom.format('YYYY-MM-DDTHH:mm:ss.SSS'), formats[i][1], "moment should be able to parse ISO in UTC " + formats[i][0] + 'Z'); + + mom = moment(formats[i][0] + ' Z').utc(); + test.equal(mom.format('YYYY-MM-DDTHH:mm:ss.SSS'), formats[i][1], "moment should be able to parse ISO in UTC " + formats[i][0] + ' Z'); } test.done(); },