Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding hooks for external libs to supply timezone name and timezone abbreviations #777

Merged
merged 1 commit into from May 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions moment.js
Expand Up @@ -199,6 +199,12 @@
}
return b + leftZeroFill(~~(10 * a / 6), 4);
},
z : function () {
return this.zoneAbbr();
},
zz : function () {
return this.zoneName();
},
X : function () {
return this.unix();
}
Expand Down Expand Up @@ -1379,6 +1385,14 @@
return this;
},

zoneAbbr : function () {
return this._isUTC ? "UTC" : "";
},

zoneName : function () {
return this._isUTC ? "Coordinated Universal Time" : "";
},

daysInMonth : function () {
return moment.utc([this.year(), this.month() + 1, 0]).date();
},
Expand Down
16 changes: 16 additions & 0 deletions test/moment/zones.js
Expand Up @@ -398,6 +398,22 @@ exports.zones = {

moment.updateOffset = oldOffset;

test.done();
},

"zone names" : function (test) {
test.expect(8);

test.equal(moment().zoneAbbr(), "", "Local zone abbr should be empty");
test.equal(moment().format('z'), "", "Local zone formatted abbr should be empty");
test.equal(moment().zoneName(), "", "Local zone name should be empty");
test.equal(moment().format('zz'), "", "Local zone formatted name should be empty");

test.equal(moment.utc().zoneAbbr(), "UTC", "UTC zone abbr should be UTC");
test.equal(moment.utc().format('z'), "UTC", "UTC zone formatted abbr should be UTC");
test.equal(moment.utc().zoneName(), "Coordinated Universal Time", "UTC zone abbr should be Coordinated Universal Time");
test.equal(moment.utc().format('zz'), "Coordinated Universal Time", "UTC zone formatted abbr should be Coordinated Universal Time");

test.done();
}

Expand Down