From: pimterry Date: Wed, 11 Dec 2013 07:56:21 +0000 (+0000) Subject: Parse for tz from the right in zone(), fixes #1336 X-Git-Tag: 2.5.0^2~6^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=db05dae1bbe03f3ce6c319868b9ff607202b5a53;p=thirdparty%2Fmoment.git Parse for tz from the right in zone(), fixes #1336 --- diff --git a/moment.js b/moment.js index 79f8e831d..d98f06ed3 100644 --- a/moment.js +++ b/moment.js @@ -49,7 +49,7 @@ parseTokenOneToSixDigits = /[+\-]?\d{1,6}/, // -999,999 - 999,999 parseTokenDigits = /\d+/, // nonzero number of digits parseTokenWord = /[0-9]*['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}/i, // any word (or two) characters or numbers including two/three word month in arabic. - parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/i, // +00:00 -00:00 +0000 -0000 or Z + parseTokenTimezone = /Z|[\+\-]\d\d:?\d\d/gi, // +00:00 -00:00 +0000 -0000 or Z parseTokenT = /T/i, // T (ISO separator) parseTokenTimestampMs = /[\+\-]?\d+(\.\d{1,3})?/, // 123456789 123456789.123 @@ -986,8 +986,10 @@ } function timezoneMinutesFromString(string) { - var tzchunk = (parseTokenTimezone.exec(string) || [])[0], - parts = (tzchunk + '').match(parseTimezoneChunker) || ['-', 0, 0], + string = string || ""; + var possibleTzMatches = (string.match(parseTokenTimezone) || []), + tzChunk = possibleTzMatches[possibleTzMatches.length - 1] || [], + parts = (tzChunk + '').match(parseTimezoneChunker) || ['-', 0, 0], minutes = +(parts[1] * 60) + toInt(parts[2]); return parts[0] === '+' ? -minutes : minutes; @@ -1235,7 +1237,7 @@ for (i = 0; i < tokens.length; i++) { token = tokens[i]; - parsedInput = (getParseRegexForToken(token, config).exec(string) || [])[0]; + parsedInput = (string.match(getParseRegexForToken(token, config)) || [])[0]; if (parsedInput) { skipped = string.substr(0, string.indexOf(parsedInput)); if (skipped.length > 0) { @@ -1353,7 +1355,7 @@ break; } } - if (parseTokenTimezone.exec(string)) { + if (string.match(parseTokenTimezone)) { config._f += "Z"; } makeDateFromStringAndFormat(config); diff --git a/test/moment/zones.js b/test/moment/zones.js index 341c38231..4a7770fd9 100644 --- a/test/moment/zones.js +++ b/test/moment/zones.js @@ -62,6 +62,9 @@ exports.zones = { zone.zone("2013-03-07T07:00:00+0100"); test.equal(zone.zone(), -60, "set the zone with a string that uses the +0000 syntax"); + zone.zone("03-07-2013T07:00:00-08:00"); + test.equal(zone.zone(), 480, "set the zone with a string with a non-ISO 8601 date"); + test.done(); },