[Time API] Fixed static code analysis issues

This commit is contained in:
Henry
2017-05-01 13:29:14 -07:00
parent 37c9c6dfaf
commit 46a51bd8db
13 changed files with 64 additions and 51 deletions

View File

@ -19,6 +19,7 @@
* this source code distribution or the Licensing information page available * this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information. * at runtime from the About dialog for additional information.
*****************************************************************************/ *****************************************************************************/
/* global console*/
define( define(
[ [
@ -235,7 +236,7 @@ define(
timeSystemsForClocks[clockKey] = timeSystemsForClocks[clockKey] || []; timeSystemsForClocks[clockKey] = timeSystemsForClocks[clockKey] || [];
timeSystemsForClocks[clockKey].push(timeSystem); timeSystemsForClocks[clockKey].push(timeSystem);
} else if (menuOption.clock !== undefined) { } else if (menuOption.clock !== undefined) {
console.log('Unknown clock "' + clockKey + '", has it been registered?'); console.error('Unknown clock "' + clockKey + '", has it been registered?');
} }
}.bind(this)); }.bind(this));
@ -389,15 +390,13 @@ define(
config = this.getConfig(selectedTimeSystem, clock); config = this.getConfig(selectedTimeSystem, clock);
if (clock === undefined) { if (clock === undefined) {
var bounds = config.bounds; this.timeAPI.timeSystem(selectedTimeSystem, config.bounds);
this.timeAPI.timeSystem(selectedTimeSystem, bounds);
} else { } else {
//When time system changes, some start bounds need to be provided //When time system changes, some start bounds need to be provided
var bounds = { this.timeAPI.timeSystem(selectedTimeSystem, {
start: clock.currentValue() + config.clockOffsets.start, start: clock.currentValue() + config.clockOffsets.start,
end: clock.currentValue() + config.clockOffsets.end end: clock.currentValue() + config.clockOffsets.end
}; });
this.timeAPI.timeSystem(selectedTimeSystem, bounds);
} }
} }

View File

@ -323,7 +323,9 @@ define([
TelemetryAPI.prototype.addFormat = function (format) { TelemetryAPI.prototype.addFormat = function (format) {
this.MCT.legacyExtension('formats', { this.MCT.legacyExtension('formats', {
key: format.key, key: format.key,
implementation: function () { return format } implementation: function () {
return format;
}
}); });
}; };

View File

@ -280,7 +280,7 @@ define(['EventEmitter'], function (EventEmitter) {
throw "Unknown time system " + timeSystem.key + ". Has it been registered with 'addTimeSystem'?"; throw "Unknown time system " + timeSystem.key + ". Has it been registered with 'addTimeSystem'?";
} }
} else { } else {
throw "Attempt to set invalid time system in Time API. Please provide a previously registered time system object or key" throw "Attempt to set invalid time system in Time API. Please provide a previously registered time system object or key";
} }
this.system = timeSystem; this.system = timeSystem;
@ -353,7 +353,7 @@ define(['EventEmitter'], function (EventEmitter) {
} }
} else if (typeof keyOrClock === 'object') { } else if (typeof keyOrClock === 'object') {
clock = keyOrClock; clock = keyOrClock;
if (!clocks.has(clock.key)){ if (!this.clocks.has(clock.key)) {
throw "Unknown clock '" + keyOrClock.key + "'. Has it been registered with 'addClock'?"; throw "Unknown clock '" + keyOrClock.key + "'. Has it been registered with 'addClock'?";
} }
} }
@ -380,7 +380,7 @@ define(['EventEmitter'], function (EventEmitter) {
this.emit("clock", this.activeClock); this.emit("clock", this.activeClock);
} else if (arguments.length === 1) { } else if (arguments.length === 1) {
throw "When setting the clock, clock offsets must also be provided" throw "When setting the clock, clock offsets must also be provided";
} }
return this.activeClock; return this.activeClock;

View File

@ -78,7 +78,7 @@ define(['./TimeAPI'], function (TimeAPI) {
api.addTimeSystem(timeSystem); api.addTimeSystem(timeSystem);
expect(api.timeSystem()).not.toBe(timeSystemKey); expect(api.timeSystem()).not.toBe(timeSystemKey);
expect(function () { expect(function () {
api.timeSystem(timeSystemKey) api.timeSystem(timeSystemKey);
}).toThrow(); }).toThrow();
expect(api.timeSystem()).not.toBe(timeSystemKey); expect(api.timeSystem()).not.toBe(timeSystemKey);
}); });
@ -130,7 +130,7 @@ define(['./TimeAPI'], function (TimeAPI) {
"off", "off",
"currentValue" "currentValue"
]); ]);
mockTickSource.key = 'mockTickSource' mockTickSource.key = 'mockTickSource';
}); });
describe(" when enabling a tick source", function () { describe(" when enabling a tick source", function () {
@ -139,7 +139,7 @@ define(['./TimeAPI'], function (TimeAPI) {
var mockOffsets = { var mockOffsets = {
start: 0, start: 0,
end: 0 end: 0
} };
beforeEach(function () { beforeEach(function () {
mockTickSource = jasmine.createSpyObj("clock", [ mockTickSource = jasmine.createSpyObj("clock", [
@ -205,7 +205,7 @@ define(['./TimeAPI'], function (TimeAPI) {
api.on("bounds", boundsCallback); api.on("bounds", boundsCallback);
tickCallback = mockTickSource.on.mostRecentCall.args[1] tickCallback = mockTickSource.on.mostRecentCall.args[1];
tickCallback(1000); tickCallback(1000);
expect(boundsCallback).toHaveBeenCalledWith({ expect(boundsCallback).toHaveBeenCalledWith({
start: 900, start: 900,

View File

@ -28,6 +28,6 @@ define([
return function () { return function () {
return function (openmct) { return function (openmct) {
openmct.time.addClock(new LADClock()); openmct.time.addClock(new LADClock());
} };
}; };
}); });

View File

@ -57,7 +57,7 @@ define([
* @private * @private
*/ */
function getScaledFormat(d) { function getScaledFormat(d) {
var m = moment.utc(d); var momentified = moment.utc(d);
/** /**
* Uses logic from d3 Time-Scales, v3 of the API. See * Uses logic from d3 Time-Scales, v3 of the API. See
* https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Scales.md * https://github.com/d3/d3-3.x-api-reference/blob/master/Time-Scales.md
@ -65,23 +65,35 @@ define([
* Licensed * Licensed
*/ */
return [ return [
[".SSS", function(m) { return m.milliseconds(); }], [".SSS", function (m) {
[":ss", function(m) { return m.seconds(); }], return m.milliseconds();
["hh:mma", function(m) { return m.minutes(); }], }],
["hha", function(m) { return m.hours(); }], [":ss", function (m) {
return m.seconds();
}],
["hh:mma", function (m) {
return m.minutes();
}],
["hha", function (m) {
return m.hours();
}],
["ddd DD", function (m) { ["ddd DD", function (m) {
return m.days() && return m.days() &&
m.date() != 1; m.date() !== 1;
}],
["MMM DD", function (m) {
return m.date() !== 1;
}], }],
["MMM DD", function(m) { return m.date() != 1; }],
["MMMM", function (m) { ["MMMM", function (m) {
return m.month(); return m.month();
}], }],
["YYYY", function() { return true; }] ["YYYY", function () {
return true;
}]
].filter(function (row) { ].filter(function (row) {
return row[1](m); return row[1](momentified);
})[0][0]; })[0][0];
}; }
/** /**
* *

View File

@ -35,6 +35,6 @@ define([
key: 'local-format', key: 'local-format',
implementation: LocalTimeFormat implementation: LocalTimeFormat
}); });
} };
}; };
}); });

View File

@ -81,13 +81,13 @@ define([], function () {
bounds = { bounds = {
start: clock.currentValue() + clockOffsets.start, start: clock.currentValue() + clockOffsets.start,
end: clock.currentValue() + clockOffsets.end end: clock.currentValue() + clockOffsets.end
} };
} }
openmct.time.timeSystem(timeSystem, bounds); openmct.time.timeSystem(timeSystem, bounds);
} else { } else {
throw 'Invalid time conductor configuration. Please define defaults for time system "' + timeSystem.key + '"'; throw 'Invalid time conductor configuration. Please define defaults for time system "' + timeSystem.key + '"';
} }
}); });
} };
} };
}); });

View File

@ -44,7 +44,7 @@ define([
* @memberof platform/commonUI/formats * @memberof platform/commonUI/formats
*/ */
function DurationFormat() { function DurationFormat() {
this.key = "duration" this.key = "duration";
} }
DurationFormat.prototype.format = function (value) { DurationFormat.prototype.format = function (value) {

View File

@ -24,7 +24,7 @@ define([
"./UTCTimeSystem", "./UTCTimeSystem",
"./LocalClock", "./LocalClock",
"./UTCTimeFormat", "./UTCTimeFormat",
"./DurationFormat", "./DurationFormat"
], function ( ], function (
UTCTimeSystem, UTCTimeSystem,
LocalClock, LocalClock,
@ -47,6 +47,6 @@ define([
"key": "DEFAULT_TIME_FORMAT", "key": "DEFAULT_TIME_FORMAT",
"value": "utc" "value": "utc"
}); });
} };
}; };
}); });