diff --git a/src/api/time/TimeAPI.js b/src/api/time/TimeAPI.js index 8d73a99722..18c26fc99d 100644 --- a/src/api/time/TimeAPI.js +++ b/src/api/time/TimeAPI.js @@ -239,7 +239,13 @@ define(['EventEmitter'], function (EventEmitter) { * @method timeSystem */ TimeAPI.prototype.timeSystem = function (timeSystemOrKey, bounds) { - if (arguments.length >= 2) { + if (arguments.length >= 1) { + if (arguments.length === 1 && !this.activeClock) { + throw new Error( + "Must specify bounds when changing time system without " + + "an active clock." + ); + } var timeSystem; if (timeSystemOrKey === undefined) { @@ -274,10 +280,10 @@ define(['EventEmitter'], function (EventEmitter) { * Time System * */ this.emit('timeSystem', this.system); - this.bounds(bounds); + if (bounds) { + this.bounds(bounds); + } - } else if (arguments.length === 1) { - throw new Error('Must set bounds when changing time system'); } return this.system; diff --git a/src/api/time/TimeAPISpec.js b/src/api/time/TimeAPISpec.js index 1ea7c4b219..6efbbfd490 100644 --- a/src/api/time/TimeAPISpec.js +++ b/src/api/time/TimeAPISpec.js @@ -25,6 +25,8 @@ define(['./TimeAPI'], function (TimeAPI) { var api, timeSystemKey, timeSystem, + clockKey, + clock, bounds, eventListener, toi; @@ -33,7 +35,15 @@ define(['./TimeAPI'], function (TimeAPI) { api = new TimeAPI(); timeSystemKey = "timeSystemKey"; timeSystem = {key: timeSystemKey}; - bounds = {start: 0, end: 0}; + clockKey = "someClockKey"; + clock = jasmine.createSpyObj("clock", [ + "on", + "off", + "currentValue" + ]); + clock.currentValue.andReturn(100); + clock.key = clockKey; + bounds = {start: 0, end: 1}; eventListener = jasmine.createSpy("eventListener"); toi = 111; }); @@ -74,11 +84,23 @@ define(['./TimeAPI'], function (TimeAPI) { it("Disallows setting of time system without bounds", function () { api.addTimeSystem(timeSystem); - expect(api.timeSystem()).not.toBe(timeSystemKey); + expect(api.timeSystem()).not.toBe(timeSystem); expect(function () { api.timeSystem(timeSystemKey); }).toThrow(); - expect(api.timeSystem()).not.toBe(timeSystemKey); + expect(api.timeSystem()).not.toBe(timeSystem); + }); + + it("allows setting of timesystem without bounds with clock", function () { + api.addTimeSystem(timeSystem); + api.addClock(clock); + api.clock(clockKey, {start: 0, end: 1}) + expect(api.timeSystem()).not.toBe(timeSystem); + expect(function () { + api.timeSystem(timeSystemKey); + }).not.toThrow(); + expect(api.timeSystem()).toBe(timeSystem); + }); it("Emits an event when time system changes", function () {