]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fixing #151 and hopefully #137
authorTim Wood <washwithcare@gmail.com>
Thu, 2 Feb 2012 18:01:22 +0000 (10:01 -0800)
committerTim Wood <washwithcare@gmail.com>
Thu, 2 Feb 2012 18:01:22 +0000 (10:01 -0800)
Adding some null checks and string typecasting for the timezone parser

moment.js
sitesrc/js/unit-tests.js

index c787148031f96f69c6711060dc97d6699cf24448..065665183802f33d977e519076e4c448bb4b1dda 100644 (file)
--- a/moment.js
+++ b/moment.js
                 // 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;
                 }
index 626a93cd8b140f9bad9ca844670b7a877df55b25..f35a3b43f6141d4ff3f65be34f7761a64db25007 100755 (executable)
@@ -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)),