Skip to content

Commit

Permalink
Fixing #151 and hopefully #137
Browse files Browse the repository at this point in the history
Adding some null checks and string typecasting for the timezone parser
  • Loading branch information
timrwood committed Feb 2, 2012
1 parent d3c735a commit 2ae239a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions moment.js
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions sitesrc/js/unit-tests.js
Expand Up @@ -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)),
Expand Down

0 comments on commit 2ae239a

Please sign in to comment.