]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Parse for tz from the right in zone(), fixes #1336
authorpimterry <pimterry@gmail.com>
Wed, 11 Dec 2013 07:56:21 +0000 (07:56 +0000)
committerpimterry <pimterry@gmail.com>
Sun, 15 Dec 2013 16:56:50 +0000 (16:56 +0000)
moment.js
test/moment/zones.js

index 79f8e831db1e1e1485b386dab2a0bac463943e50..d98f06ed3300163489fec9868490a4eade671785 100644 (file)
--- 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
 
     }
 
     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;
 
         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) {
                     break;
                 }
             }
-            if (parseTokenTimezone.exec(string)) {
+            if (string.match(parseTokenTimezone)) {
                 config._f += "Z";
             }
             makeDateFromStringAndFormat(config);
index 341c38231b11afbd77eae135699e05868dad7898..4a7770fd9f6418c2c3d070568776c3e1341623ba 100644 (file)
@@ -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();
     },