diff --git a/moment-timezone.js b/moment-timezone.js index e53f3256..25a9b6af 100644 --- a/moment-timezone.js +++ b/moment-timezone.js @@ -161,6 +161,34 @@ } }, + offsetChanges: function (from, to) { + var fromIndex = this._index(from), + toIndex = this._index(to), + changes = [], + i; + for (i = fromIndex; i < toIndex; i++) changes.push(this.untils[i]); + return changes; + }, + + offsetNext: function (timestamp) { + var index = this._index(timestamp); + if (index === undefined) { + return undefined; + } + return this.untils[index]; + }, + + offsetPrevious: function (timestamp) { + var index = this._index(timestamp); + if (index === undefined) { + return undefined; + } + if (index < 1) { + return undefined; + } + return this.untils[index-1]; + }, + parse : function (timestamp) { var target = +timestamp, offsets = this.offsets, diff --git a/tests/moment-timezone/zone.js b/tests/moment-timezone/zone.js index 8dac8c14..9d8d32ce 100644 --- a/tests/moment-timezone/zone.js +++ b/tests/moment-timezone/zone.js @@ -38,6 +38,43 @@ exports.zone = { test.done(); }, + offsetChanges: function(test) { + var zone = new tz.Zone(PACKED), + from = 1200 * 60000, + to = 1400 * 60000, + expected = [ 1240 * 60000, 1340 * 60000 ]; + test.deepEqual(zone.offsetChanges(from, to), expected, "The offsetChanges from " + from + "to" + to + " should be " + expected); + from = 0; + expected = [ 1000 * 60000, 1100 * 60000, 1240 * 60000, 1340 * 60000 ]; + test.deepEqual(zone.offsetChanges(from, to), expected, "The offsetChanges from " + from + "to" + to + " should be " + expected); + to = 1500 * 60000; + expected = [ 1000 * 60000, 1100 * 60000, 1240 * 60000, 1340 * 60000, 1480 * 60000 ]; + test.deepEqual(zone.offsetChanges(from, to), expected, "The offsetChanges from " + from + "to" + to + " should be " + expected); + test.done(); + }, + + offsetNext: function(test) { + var zone = new tz.Zone(PACKED), + timestamp = 1050 * 60000, + expected = 1100 * 60000; + test.equal(zone.offsetNext(timestamp), expected, "The offsetNext of " + timestamp + " should be " + expected); + timestamp = 1150 * 60000; + expected = 1240 * 60000; + test.equal(zone.offsetNext(timestamp), expected, "The offsetNext of " + timestamp + " should be " + expected); + test.done(); + }, + + offsetPrevious: function(test) { + var zone = new tz.Zone(PACKED), + timestamp = 1050 * 60000, + expected = 1000 * 60000; + test.equal(zone.offsetPrevious(timestamp), expected, "The offsetNext of " + timestamp + " should be " + expected); + timestamp = 1150 * 60000; + expected = 1100 * 60000; + test.equal(zone.offsetPrevious(timestamp), expected, "The offsetNext of " + timestamp + " should be " + expected); + test.done(); + }, + abbr : function (test) { var zone = new tz.Zone(PACKED), tests = [