[Time Conductor] Use dateService from TimeRangeController

This commit is contained in:
Victor Woeltjen
2015-10-22 12:17:08 -07:00
parent 0d47b7c47d
commit 117470068a
3 changed files with 32 additions and 8 deletions

View File

@ -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",

View File

@ -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;
} }
); );

View File

@ -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 () {