]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Adding hooks for external libs to supply timezone name and timezone abbreviations 777/head
authorTim Wood <washwithcare@gmail.com>
Sat, 11 May 2013 21:08:42 +0000 (11:08 -1000)
committerTim Wood <washwithcare@gmail.com>
Sat, 11 May 2013 21:08:42 +0000 (11:08 -1000)
moment.js
test/moment/zones.js

index 0bb255cf51581a7da8ab38044e4c65119ac59ba1..6284d3677191602605fbc1e549cb1a88e7ba15b8 100644 (file)
--- a/moment.js
+++ b/moment.js
                 }
                 return b + leftZeroFill(~~(10 * a / 6), 4);
             },
+            z : function () {
+                return this.zoneAbbr();
+            },
+            zz : function () {
+                return this.zoneName();
+            },
             X    : function () {
                 return this.unix();
             }
             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();
         },
index 8adecbf58814cf0bc37183a0bc2aa8060534202b..133de2e46bd0a91c1ea4b048693734a17ea6fa6a 100644 (file)
@@ -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();
     }