diff --git a/platform/commonUI/general/bundle.json b/platform/commonUI/general/bundle.json index eee42ef4cd..09e523d105 100644 --- a/platform/commonUI/general/bundle.json +++ b/platform/commonUI/general/bundle.json @@ -53,7 +53,7 @@ { "key": "TimeRangeController", "implementation": "controllers/TimeRangeController.js", - "depends": [ "$scope", "formatService", "now" ] + "depends": [ "$scope", "formatService", "DEFAULT_TIME_FORMAT", "now" ] }, { "key": "DateTimePickerController", @@ -63,7 +63,7 @@ { "key": "DateTimeFieldController", "implementation": "controllers/DateTimeFieldController.js", - "depends": [ "$scope", "formatService" ] + "depends": [ "$scope", "formatService", "DEFAULT_TIME_FORMAT" ] }, { "key": "TreeNodeController", diff --git a/platform/commonUI/general/src/controllers/DateTimeFieldController.js b/platform/commonUI/general/src/controllers/DateTimeFieldController.js index 5c48cc2453..950dcc21e2 100644 --- a/platform/commonUI/general/src/controllers/DateTimeFieldController.js +++ b/platform/commonUI/general/src/controllers/DateTimeFieldController.js @@ -26,7 +26,8 @@ define( function () { 'use strict'; - var DEFAULT_FORMAT = 'utc'; + var UNRECOGNIZED_FORMAT_ERROR = + "Unrecognized format for date-time field."; /** * Controller to support the date-time entry field. @@ -40,12 +41,14 @@ define( * @constructor * @memberof platform/commonUI/general */ - function DateTimeFieldController($scope, formatService) { - var formatter = formatService.getFormat(DEFAULT_FORMAT); + function DateTimeFieldController($scope, formatService, defaultFormat) { + var formatter = formatService.getFormat(defaultFormat); function setFormat(format) { - formatter = formatService.getFormat(format) || - formatService.getFormat(DEFAULT_FORMAT); + formatter = formatService.getFormat(format || defaultFormat); + if (!formatter) { + throw new Error(UNRECOGNIZED_FORMAT_ERROR); + } } function updateFromModel(value) { diff --git a/platform/commonUI/general/src/controllers/TimeRangeController.js b/platform/commonUI/general/src/controllers/TimeRangeController.js index 85fad1100c..fd30d3a231 100644 --- a/platform/commonUI/general/src/controllers/TimeRangeController.js +++ b/platform/commonUI/general/src/controllers/TimeRangeController.js @@ -26,20 +26,22 @@ define( function (moment) { "use strict"; - var DEFAULT_FORMAT = "utc", - TICK_SPACING_PX = 150; + var TICK_SPACING_PX = 150, + UNRECOGNIZED_FORMAT_ERROR = + "Unrecognized format for time range control."; + /** * Controller used by the `time-controller` template. * @memberof platform/commonUI/general * @constructor */ - function TimeRangeController($scope, formatService, now) { + function TimeRangeController($scope, formatService, defaultFormat, now) { var tickCount = 2, innerMinimumSpan = 1000, // 1 second outerMinimumSpan = 1000 * 60 * 60, // 1 hour initialDragValue, - formatter = formatService.getFormat(DEFAULT_FORMAT); + formatter = formatService.getFormat(defaultFormat); function formatTimestamp(ts) { return formatter.format(ts); @@ -212,8 +214,11 @@ define( } function updateFormat(key) { - formatter = formatService.getFormat(key) || - formatService.getFormat(DEFAULT_FORMAT); + formatter = formatService.getFormat(key || defaultFormat); + + if (!formatter) { + throw new Error(UNRECOGNIZED_FORMAT_ERROR); + } updateViewForInnerSpanFromModel($scope.ngModel); updateTicks();