Skip to content

Commit

Permalink
Deprecating format tokens z zz
Browse files Browse the repository at this point in the history
  • Loading branch information
timrwood committed Apr 11, 2012
1 parent a932ebe commit 9b56710
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
9 changes: 0 additions & 9 deletions moment.js
Expand Up @@ -24,11 +24,6 @@

// format tokens
formattingTokens = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|SS?S?|zz?|ZZ?|LT|LL?L?L?)/g,

// regexes for format z, zz
// TODO: When we drop support for z and zz, remove these variables
nonuppercaseLetters = /[^A-Z]/g,
timezoneRegex = /\([A-Za-z ]+\)|:[0-9]{2} [A-Z]{3} /g,

// parsing tokens
parseMultipleFormatChunker = /([0-9a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)/gi,
Expand Down Expand Up @@ -229,10 +224,6 @@
case 'SSS' :
return leftZeroFill(currentMilliseconds, 3);
// TIMEZONE
case 'zz' :
// depreciating 'zz' fall through to 'z'
case 'z' :
return (m._d.toString().match(timezoneRegex) || [''])[0].replace(nonuppercaseLetters, '');
case 'Z' :
return (currentZone < 0 ? '-' : '+') + leftZeroFill(~~(Math.abs(currentZone) / 60), 2) + ':' + leftZeroFill(~~(Math.abs(currentZone) % 60), 2);
case 'ZZ' :
Expand Down
4 changes: 1 addition & 3 deletions test/moment/format.js
Expand Up @@ -35,15 +35,13 @@ exports.format = {
},

"format timezone" : function(test) {
test.expect(4);
test.expect(2);

var b = moment(new Date(2010, 1, 14, 15, 25, 50, 125));
var explanation = 'moment().format("z") = ' + b.format('z') + ' It should be something like "PST"'
if (moment().zone() === -60) {
explanation += "For UTC+1 this is a known issue, see https://github.com/timrwood/moment/issues/162";
}
test.ok(b.format('z').match(/^[A-Z]{3,6}$/), explanation);
test.ok(b.format('zz').match(/^[A-Z]{3,6}$/), explanation);
test.ok(b.format('Z').match(/^[\+\-]\d\d:\d\d$/), b.format('Z') + ' should be something like "+07:30"');
test.ok(b.format('ZZ').match(/^[\+\-]\d{4}$/), b.format('ZZ') + ' should be something like "+0700"');
test.done();
Expand Down

0 comments on commit 9b56710

Please sign in to comment.