mirror of
https://github.com/nasa/openmct.git
synced 2025-06-14 05:08:15 +00:00
[Time Conductor] Use dateService from TimeRangeController
This commit is contained in:
@ -66,7 +66,7 @@
|
|||||||
{
|
{
|
||||||
"key": "TimeRangeController",
|
"key": "TimeRangeController",
|
||||||
"implementation": "controllers/TimeRangeController.js",
|
"implementation": "controllers/TimeRangeController.js",
|
||||||
"depends": [ "$scope", "now" ]
|
"depends": [ "$scope", "dateService", "now" ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "DateTimePickerController",
|
"key": "DateTimePickerController",
|
||||||
|
@ -30,23 +30,28 @@ define(
|
|||||||
TICK_SPACING_PX = 150;
|
TICK_SPACING_PX = 150;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Controller used by the `time-controller` template.
|
||||||
* @memberof platform/commonUI/general
|
* @memberof platform/commonUI/general
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function TimeConductorController($scope, now) {
|
function TimeRangeController($scope, dateService, now) {
|
||||||
var tickCount = 2,
|
var tickCount = 2,
|
||||||
innerMinimumSpan = 1000, // 1 second
|
innerMinimumSpan = 1000, // 1 second
|
||||||
outerMinimumSpan = 1000 * 60 * 60, // 1 hour
|
outerMinimumSpan = 1000 * 60 * 60, // 1 hour
|
||||||
initialDragValue;
|
initialDragValue;
|
||||||
|
|
||||||
|
function timeSystemKey() {
|
||||||
|
return ($scope.parameters || {}).domain;
|
||||||
|
}
|
||||||
|
|
||||||
function formatTimestamp(ts) {
|
function formatTimestamp(ts) {
|
||||||
return moment.utc(ts).format(DATE_FORMAT);
|
return dateService.format(ts, timeSystemKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTimestamp(text) {
|
function parseTimestamp(text) {
|
||||||
var m = moment.utc(text, DATE_FORMAT);
|
var key = timeSystemKey();
|
||||||
if (m.isValid()) {
|
if (dateService.validate(text, key)) {
|
||||||
return m.valueOf();
|
return dateService.parse(text, key);
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Could not parse " + text);
|
throw new Error("Could not parse " + text);
|
||||||
}
|
}
|
||||||
@ -297,6 +302,6 @@ define(
|
|||||||
$scope.$watch("boundsModel.end", updateEndFromText);
|
$scope.$watch("boundsModel.end", updateEndFromText);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TimeConductorController;
|
return TimeRangeController;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -33,6 +33,7 @@ define(
|
|||||||
|
|
||||||
describe("The TimeRangeController", function () {
|
describe("The TimeRangeController", function () {
|
||||||
var mockScope,
|
var mockScope,
|
||||||
|
mockDateService,
|
||||||
mockNow,
|
mockNow,
|
||||||
controller;
|
controller;
|
||||||
|
|
||||||
@ -57,8 +58,26 @@ define(
|
|||||||
"$scope",
|
"$scope",
|
||||||
[ "$apply", "$watch", "$watchCollection" ]
|
[ "$apply", "$watch", "$watchCollection" ]
|
||||||
);
|
);
|
||||||
|
mockDateService = jasmine.createSpyObj(
|
||||||
|
"dateService",
|
||||||
|
[ "validate", "format", "parse" ]
|
||||||
|
);
|
||||||
|
mockDateService.validate.andCallFake(function (text) {
|
||||||
|
return moment.utc(text).isValid();
|
||||||
|
});
|
||||||
|
mockDateService.parse.andCallFake(function (text) {
|
||||||
|
return moment.utc(text).valueOf();
|
||||||
|
});
|
||||||
|
mockDateService.format.andCallFake(function (value) {
|
||||||
|
return moment.utc(value).format("YYYY-MM-DD HH:mm:ss");
|
||||||
|
});
|
||||||
mockNow = jasmine.createSpy('now');
|
mockNow = jasmine.createSpy('now');
|
||||||
controller = new TimeRangeController(mockScope, mockNow);
|
|
||||||
|
controller = new TimeRangeController(
|
||||||
|
mockScope,
|
||||||
|
mockDateService,
|
||||||
|
mockNow
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("watches the model that was passed in", function () {
|
it("watches the model that was passed in", function () {
|
||||||
|
Reference in New Issue
Block a user