mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 09:26:45 +00:00
[Time Conductor] Remove dateService
Replaced by timeService
This commit is contained in:
parent
67cf8d8cee
commit
111b3bac09
@ -15,19 +15,6 @@
|
||||
"depends": [ "$document", "$window" ]
|
||||
}
|
||||
],
|
||||
"components": [
|
||||
{
|
||||
"type": "aggregator",
|
||||
"provides": "dateService",
|
||||
"implementation": "services/DateAggregator.js"
|
||||
},
|
||||
{
|
||||
"type": "provider",
|
||||
"provides": "dateService",
|
||||
"implementation": "services/UTCDateProvider.js",
|
||||
"priority": "fallback"
|
||||
}
|
||||
],
|
||||
"runs": [
|
||||
{
|
||||
"implementation": "StyleSheetLoader.js",
|
||||
|
@ -1,118 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
/*global define*/
|
||||
|
||||
define([
|
||||
|
||||
], function (
|
||||
) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Formats dates for display and parses dates from user input,
|
||||
* varying by a chosen time system.
|
||||
*
|
||||
* Time systems are typically specified as `system` properties
|
||||
* of domains in {@link TelemetryDomainMetadata}.
|
||||
*
|
||||
* If omitted/left undefined, the time system is presumed to be UTC time,
|
||||
* with its numeric interpretation being milliseconds since the
|
||||
* start of 1970.
|
||||
*
|
||||
* @interface DateService
|
||||
*/
|
||||
|
||||
/**
|
||||
* Check if the provided text can be parsed into a numeric
|
||||
* representation of a time in the specified time system.
|
||||
* @method validate
|
||||
* @memberof DateService#
|
||||
* @param {string} text the text to validate
|
||||
* @param {string} [key] a key identifying the time system
|
||||
* @returns {boolean} true if the text can be parsed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Parse the provided into a numeric representation of a time
|
||||
* in the specified time system.
|
||||
*
|
||||
* Behavior of this method for invalid text is undefined; use
|
||||
* the `validate` method to check for validity first.
|
||||
*
|
||||
* @method parse
|
||||
* @memberof DateService#
|
||||
* @param {string} text the text to parse
|
||||
* @param {string} [key] a key identifying the time system
|
||||
* @returns {number} a numeric representation of the date/time
|
||||
*/
|
||||
|
||||
/**
|
||||
* Format the provided numeric representation of a time
|
||||
* into a human-readable string appropriate for that time system.
|
||||
*
|
||||
* If the time system is not recognized, the return value will be
|
||||
* `undefined`.
|
||||
*
|
||||
* @method format
|
||||
* @memberof DateService#
|
||||
* @param {number} value the time value to format
|
||||
* @param {string} [key] a key identifying the time system
|
||||
* @returns {string} a human-readable representation of the date/time
|
||||
*/
|
||||
|
||||
/**
|
||||
* Composites multiple DateService implementations such that
|
||||
* they can be used as one.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
*/
|
||||
function DateAggregator(dateProviders) {
|
||||
this.dateProviders = dateProviders;
|
||||
}
|
||||
|
||||
DateAggregator.prototype.validate = function (text, key) {
|
||||
return this.dateProviders.some(function (provider) {
|
||||
return provider.validate(text, key);
|
||||
});
|
||||
};
|
||||
|
||||
DateAggregator.prototype.format = function (value, key) {
|
||||
var i, text;
|
||||
for (i = 0; i < this.dateProviders.length; i += 1) {
|
||||
text = this.dateProviders[i].format(value, key);
|
||||
if (text !== undefined) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
DateAggregator.prototype.parse = function (text, key) {
|
||||
var i;
|
||||
for (i = 0; i < this.dateProviders.length; i += 1) {
|
||||
if (this.dateProviders[i].validate(text, key)) {
|
||||
return this.dateProviders[i].parse(text, key);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return DateAggregator;
|
||||
});
|
@ -1,64 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
/*global define*/
|
||||
|
||||
define([
|
||||
'moment'
|
||||
], function (
|
||||
moment
|
||||
) {
|
||||
"use strict";
|
||||
|
||||
var DATE_FORMAT = "YYYY-MM-DD HH:mm:ss",
|
||||
DATE_FORMATS = [
|
||||
DATE_FORMAT,
|
||||
"YYYY-MM-DD HH:mm:ss",
|
||||
"YYYY-MM-DD HH:mm",
|
||||
"YYYY-MM-DD"
|
||||
];
|
||||
|
||||
/**
|
||||
* Composites multiple DateService implementations such that
|
||||
* they can be used as one.
|
||||
* @memberof platform/commonUI/general
|
||||
* @constructor
|
||||
* @implements {DateService}
|
||||
*/
|
||||
function UTCDateProvider() {
|
||||
}
|
||||
|
||||
UTCDateProvider.prototype.validate = function (text, key) {
|
||||
return key === undefined && moment.utc(text, DATE_FORMATS).isValid();
|
||||
};
|
||||
|
||||
UTCDateProvider.prototype.format = function (value, key) {
|
||||
return key === undefined ?
|
||||
moment.utc(value).format(DATE_FORMAT) :
|
||||
undefined;
|
||||
};
|
||||
|
||||
UTCDateProvider.prototype.parse = function (text, key) {
|
||||
return key === undefined && moment.utc(text, DATE_FORMATS).valueOf();
|
||||
};
|
||||
|
||||
return UTCDateProvider;
|
||||
});
|
@ -1,94 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
|
||||
|
||||
define(
|
||||
["../../src/services/DateAggregator"],
|
||||
function (DateAggregator) {
|
||||
'use strict';
|
||||
|
||||
var DATE_SERVICE_METHODS = [ "format", "validate", "parse" ];
|
||||
|
||||
describe("DateAggregator", function () {
|
||||
var mockProviders,
|
||||
dateAggregator;
|
||||
|
||||
beforeEach(function () {
|
||||
mockProviders = [ 'a', 'b', 'c', undefined ].map(function (k, i) {
|
||||
var mockProvider = jasmine.createSpyObj(
|
||||
'provider-' + k,
|
||||
DATE_SERVICE_METHODS
|
||||
);
|
||||
|
||||
mockProvider.format.andCallFake(function (value, key) {
|
||||
return key === k ?
|
||||
("Formatted " + value + " for " + k) :
|
||||
undefined;
|
||||
});
|
||||
|
||||
mockProvider.parse.andCallFake(function (text, key) {
|
||||
return key === k ? i : undefined;
|
||||
});
|
||||
|
||||
mockProvider.validate.andCallFake(function (text, key) {
|
||||
return key === k;
|
||||
});
|
||||
|
||||
return mockProvider;
|
||||
});
|
||||
|
||||
dateAggregator = new DateAggregator(mockProviders);
|
||||
});
|
||||
|
||||
it("formats dates using the first provider which gives a result", function () {
|
||||
expect(dateAggregator.format(42, "a"))
|
||||
.toEqual("Formatted 42 for a");
|
||||
expect(dateAggregator.format(12321, "b"))
|
||||
.toEqual("Formatted 12321 for b");
|
||||
expect(dateAggregator.format(1977, "c"))
|
||||
.toEqual("Formatted 1977 for c");
|
||||
expect(dateAggregator.format(0))
|
||||
.toEqual("Formatted 0 for undefined");
|
||||
});
|
||||
|
||||
it("parses dates using the first provider which validates", function () {
|
||||
expect(dateAggregator.parse("x", "a")).toEqual(0);
|
||||
expect(dateAggregator.parse("x", "b")).toEqual(1);
|
||||
expect(dateAggregator.parse("x", "c")).toEqual(2);
|
||||
expect(dateAggregator.parse("x")).toEqual(3);
|
||||
});
|
||||
|
||||
it("validates across all providers", function () {
|
||||
expect(dateAggregator.validate("x", "a")).toBeTruthy();
|
||||
expect(dateAggregator.validate("x", "b")).toBeTruthy();
|
||||
expect(dateAggregator.validate("x", "c")).toBeTruthy();
|
||||
expect(dateAggregator.validate("x")).toBeTruthy();
|
||||
expect(dateAggregator.validate("x", "z")).toBeFalsy();
|
||||
|
||||
mockProviders[3].validate.andReturn(false);
|
||||
expect(dateAggregator.validate("x")).toBeFalsy();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -1,67 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
||||
* as represented by the Administrator of the National Aeronautics and Space
|
||||
* Administration. All rights reserved.
|
||||
*
|
||||
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Open MCT Web includes source code licensed under additional open source
|
||||
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
||||
* this source code distribution or the Licensing information page available
|
||||
* at runtime from the About dialog for additional information.
|
||||
*****************************************************************************/
|
||||
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
|
||||
|
||||
define(
|
||||
["../../src/services/UTCDateProvider", "moment"],
|
||||
function (UTCDateProvider, moment) {
|
||||
'use strict';
|
||||
|
||||
describe("UTCDateProvider", function () {
|
||||
var testDate, testTimestamp, dateProvider;
|
||||
|
||||
beforeEach(function () {
|
||||
testDate = "1977-05-25 17:30:00";
|
||||
testTimestamp = moment.utc(testDate).valueOf();
|
||||
dateProvider = new UTCDateProvider();
|
||||
});
|
||||
|
||||
it("distinguishes valid dates from invalid dates", function () {
|
||||
expect(dateProvider.validate(testDate))
|
||||
.toBeTruthy();
|
||||
expect(dateProvider.validate("2015-garbage :00:00"))
|
||||
.toBeFalsy();
|
||||
});
|
||||
|
||||
it("parses dates to their numeric representations", function () {
|
||||
expect(dateProvider.parse(testDate)).toEqual(testTimestamp);
|
||||
});
|
||||
|
||||
it("formats to text representing UTC date/times", function () {
|
||||
var formatted = dateProvider.format(testTimestamp);
|
||||
expect(formatted).toEqual(jasmine.any(String));
|
||||
// Use moment to verify that formatted value is equal
|
||||
// to the original date/time
|
||||
expect(moment.utc(formatted).valueOf()).toEqual(testTimestamp);
|
||||
});
|
||||
|
||||
it("does not handle defined keys", function () {
|
||||
expect(dateProvider.validate(testDate, 'someKey'))
|
||||
.toBeFalsy();
|
||||
expect(dateProvider.format(testTimestamp, 'someKey'))
|
||||
.toBeUndefined();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -17,8 +17,6 @@
|
||||
"directives/MCTPopup",
|
||||
"directives/MCTResize",
|
||||
"directives/MCTScroll",
|
||||
"services/DateAggregator",
|
||||
"services/UTCDateProvider",
|
||||
"services/Popup",
|
||||
"services/PopupService",
|
||||
"services/UrlService",
|
||||
|
Loading…
x
Reference in New Issue
Block a user