]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Add isLocal(), isUtc() == isUTC(), isUtcOffset()
authorIskren Chernev <iskren.chernev@gmail.com>
Sun, 23 Nov 2014 09:36:55 +0000 (01:36 -0800)
committerIskren Chernev <iskren.chernev@gmail.com>
Wed, 24 Dec 2014 21:29:52 +0000 (13:29 -0800)
moment.js
test/moment/offset.js

index 8788830f7f79a9a67210ea1fa097791380671cb9..feee9535dc9162b61f38c8778ee902aec34f6cb4 100644 (file)
--- a/moment.js
+++ b/moment.js
             }
         },
 
+        isLocal : function () {
+            return !this._isUTC;
+        },
+
+        isUtcOffset : function () {
+            return this._isUTC;
+        },
+
+        isUtc : function () {
+            return this._isUTC && this._offset === 0;
+        },
+
         zoneAbbr : function () {
             return this._isUTC ? 'UTC' : '';
         },
     // add aliased format methods
     moment.fn.toJSON = moment.fn.toISOString;
 
+    // alias isUtc for dev-friendliness
+    moment.fn.isUTC = moment.fn.isUtc;
+
     /************************************
         Duration Prototype
     ************************************/
index 5f0f1e22ddfd3a1063665c66a2738ed9f73ec7f3..9ca46b221043f489d080e1a05ae5bbd2e6b773da 100644 (file)
@@ -35,6 +35,33 @@ exports.offset = {
         test.equal(m.clone().utcOffset('-01:30').utcOffset(), -90, 'utcOffset +01:30 is 90');
         test.equal(m.clone().utcOffset('-0130').utcOffset(), -90, 'utcOffset +0130 is 90');
 
+        test.done();
+    },
+
+    'isLocal, isUtc, isUtcOffset' : function (test) {
+        test.ok(moment().isLocal(), 'moment() creates objects in local time');
+        test.ok(!moment.utc().isLocal(), 'moment.utc creates objects NOT in local time');
+        test.ok(moment.utc().local().isLocal(), 'moment.fn.local() converts to local time');
+        test.ok(!moment().utcOffset(5).isLocal(), 'moment.fn.utcOffset(N) puts objects NOT in local time');
+        test.ok(moment().utcOffset(5).local().isLocal(), 'moment.fn.local() converts to local time');
+
+        test.ok(moment.utc().isUtc(), 'moment.utc() creates objects in utc time');
+        test.ok(moment().utcOffset(0).isUtc(), 'utcOffset(0) is equivalent to utc mode');
+        test.ok(!moment().utcOffset(1).isUtc(), 'utcOffset(1) is NOT equivalent to utc mode');
+
+        test.ok(!moment().isUtcOffset(), 'moment() creates objects NOT in utc-offset mode');
+        test.ok(moment.utc().isUtcOffset(), 'moment.utc() creates objects in utc-offset mode');
+        test.ok(moment().utcOffset(3).isUtcOffset(), 'utcOffset(N != 0) creates objects in utc-offset mode');
+        test.ok(moment().utcOffset(0).isUtcOffset(), 'utcOffset(0) creates objects in utc-offset mode');
+
+        test.done();
+    },
+
+    'isUTC' : function (test) {
+        test.ok(moment.utc().isUTC(), 'moment.utc() creates objects in utc time');
+        test.ok(moment().utcOffset(0).isUTC(), 'utcOffset(0) is equivalent to utc mode');
+        test.ok(!moment().utcOffset(1).isUTC(), 'utcOffset(1) is NOT equivalent to utc mode');
+
         test.done();
     }
 };