From 2e9286705e88faf842bca4d2221cc58c4c3ce929 Mon Sep 17 00:00:00 2001 From: Isaac Cambron Date: Mon, 16 Sep 2013 23:13:24 -0400 Subject: [PATCH] adding parseZone() --- moment.js | 11 +++++++++++ test/moment/zones.js | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/moment.js b/moment.js index 7c6b3359a..de2478404 100644 --- a/moment.js +++ b/moment.js @@ -1244,6 +1244,10 @@ return normalizeUnits(units); }; + moment.parseZone = function (input) { + return moment(input).parseZone(); + }; + /************************************ Moment Prototype ************************************/ @@ -1543,6 +1547,13 @@ return this._isUTC ? "Coordinated Universal Time" : ""; }, + parseZone : function () { + if (typeof this._i === 'string') { + this.zone(this._i); + } + return this; + }, + hasAlignedHourOffset : function (input) { if (!input) { input = 0; diff --git a/test/moment/zones.js b/test/moment/zones.js index 46a22dc85..3019b82bb 100644 --- a/test/moment/zones.js +++ b/test/moment/zones.js @@ -460,6 +460,22 @@ exports.zones = { test.equals(m.hasAlignedHourOffset(moment().zone(35)), false); test.equals(m.hasAlignedHourOffset(moment().zone(-85)), false); + test.done(); + }, + + "parse zone" : function (test) { + test.expect(2); + var m = moment("2013-01-01T00:00:00-13:00").parseZone(); + test.equal(m.zone(), 13 * 60); + test.equal(m.hours(), 0); + test.done(); + }, + + "parse zone static" : function (test) { + test.expect(2); + var m = moment.parseZone("2013-01-01T00:00:00-13:00"); + test.equal(m.zone(), 13 * 60); + test.equal(m.hours(), 0); test.done(); } }; -- 2.47.2