From e165c44d27819fa933f336f37bc3d651fb978caf Mon Sep 17 00:00:00 2001 From: Tim Wood Date: Sat, 11 May 2013 11:08:42 -1000 Subject: [PATCH] Adding hooks for external libs to supply timezone name and timezone abbreviations --- moment.js | 14 ++++++++++++++ test/moment/zones.js | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/moment.js b/moment.js index 0bb255cf5..6284d3677 100644 --- a/moment.js +++ b/moment.js @@ -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(); } @@ -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(); }, diff --git a/test/moment/zones.js b/test/moment/zones.js index 8adecbf58..133de2e46 100644 --- a/test/moment/zones.js +++ b/test/moment/zones.js @@ -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(); } -- 2.47.2