From: Iskren Chernev Date: Sun, 23 Nov 2014 09:36:55 +0000 (-0800) Subject: Add isLocal(), isUtc() == isUTC(), isUtcOffset() X-Git-Tag: 2.9.0~23^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=272fe3c6f8aff6a695564ce9856f2c549362c4b7;p=thirdparty%2Fmoment.git Add isLocal(), isUtc() == isUTC(), isUtcOffset() --- diff --git a/moment.js b/moment.js index 8788830f7..feee9535d 100644 --- a/moment.js +++ b/moment.js @@ -2467,6 +2467,18 @@ } }, + isLocal : function () { + return !this._isUTC; + }, + + isUtcOffset : function () { + return this._isUTC; + }, + + isUtc : function () { + return this._isUTC && this._offset === 0; + }, + zoneAbbr : function () { return this._isUTC ? 'UTC' : ''; }, @@ -2668,6 +2680,9 @@ // add aliased format methods moment.fn.toJSON = moment.fn.toISOString; + // alias isUtc for dev-friendliness + moment.fn.isUTC = moment.fn.isUtc; + /************************************ Duration Prototype ************************************/ diff --git a/test/moment/offset.js b/test/moment/offset.js index 5f0f1e22d..9ca46b221 100644 --- a/test/moment/offset.js +++ b/test/moment/offset.js @@ -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(); } };