From: Tim Wood Date: Thu, 2 Feb 2012 18:01:22 +0000 (-0800) Subject: Fixing #151 and hopefully #137 X-Git-Tag: 1.4.0~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2ae239a2aa1b8f6c13b8093e88edac38e59577cb;p=thirdparty%2Fmoment.git Fixing #151 and hopefully #137 Adding some null checks and string typecasting for the timezone parser --- diff --git a/moment.js b/moment.js index c78714803..065665183 100644 --- a/moment.js +++ b/moment.js @@ -290,15 +290,15 @@ // fall through to ZZ case 'ZZ' : isUsingUTC = true; - a = input.match(timezoneParseRegex); - if (a[1]) { + a = (input || '').match(timezoneParseRegex); + if (a && a[1]) { timezoneHours = ~~a[1]; } - if (a[2]) { + if (a && a[2]) { timezoneMinutes = ~~a[2]; } // reverse offsets - if (a[0] === '+') { + if (a && a[0] === '+') { timezoneHours = -timezoneHours; timezoneMinutes = -timezoneMinutes; } diff --git a/sitesrc/js/unit-tests.js b/sitesrc/js/unit-tests.js index 626a93cd8..f35a3b43f 100755 --- a/sitesrc/js/unit-tests.js +++ b/sitesrc/js/unit-tests.js @@ -430,6 +430,11 @@ test("format timezone", 4, function() { ok(b.format('ZZ').match(/^[\+\-]\d{4}$/), b.format('ZZ') + ' ---> Something like "+0700"'); }); +test("format multiple with zone", 1, function() { + var b = moment('2012-10-08 -1200', ['YYYY ZZ', 'YYYY-MM-DD ZZ']); + equals(b.format('YYYY-MM'), '2012-10', 'Parsing multiple formats should not crash with different sized formats'); +}); + test("isDST", 2, function() { // In the US 2011 March 13 is Daylight Savings Day var a = moment(new Date(2011, 2, 12, 0, 0, 0)),