From 111b3bac09a841235274cc8564dc6425f31a0b65 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 22 Oct 2015 16:27:21 -0700 Subject: [PATCH] [Time Conductor] Remove dateService Replaced by timeService --- platform/commonUI/general/bundle.json | 13 -- .../general/src/services/DateAggregator.js | 118 ------------------ .../general/src/services/UTCDateProvider.js | 64 ---------- .../test/services/DateAggregatorSpec.js | 94 -------------- .../test/services/UTCDateProviderSpec.js | 67 ---------- platform/commonUI/general/test/suite.json | 2 - 6 files changed, 358 deletions(-) delete mode 100644 platform/commonUI/general/src/services/DateAggregator.js delete mode 100644 platform/commonUI/general/src/services/UTCDateProvider.js delete mode 100644 platform/commonUI/general/test/services/DateAggregatorSpec.js delete mode 100644 platform/commonUI/general/test/services/UTCDateProviderSpec.js diff --git a/platform/commonUI/general/bundle.json b/platform/commonUI/general/bundle.json index 30057dcff1..a4d4008f3d 100644 --- a/platform/commonUI/general/bundle.json +++ b/platform/commonUI/general/bundle.json @@ -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", diff --git a/platform/commonUI/general/src/services/DateAggregator.js b/platform/commonUI/general/src/services/DateAggregator.js deleted file mode 100644 index ee01929b27..0000000000 --- a/platform/commonUI/general/src/services/DateAggregator.js +++ /dev/null @@ -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; -}); diff --git a/platform/commonUI/general/src/services/UTCDateProvider.js b/platform/commonUI/general/src/services/UTCDateProvider.js deleted file mode 100644 index 38b6c61b8b..0000000000 --- a/platform/commonUI/general/src/services/UTCDateProvider.js +++ /dev/null @@ -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; -}); diff --git a/platform/commonUI/general/test/services/DateAggregatorSpec.js b/platform/commonUI/general/test/services/DateAggregatorSpec.js deleted file mode 100644 index ba55bc907a..0000000000 --- a/platform/commonUI/general/test/services/DateAggregatorSpec.js +++ /dev/null @@ -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(); - }); - - }); - } -); diff --git a/platform/commonUI/general/test/services/UTCDateProviderSpec.js b/platform/commonUI/general/test/services/UTCDateProviderSpec.js deleted file mode 100644 index 1a1873030d..0000000000 --- a/platform/commonUI/general/test/services/UTCDateProviderSpec.js +++ /dev/null @@ -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(); - }); - - }); - } -); diff --git a/platform/commonUI/general/test/suite.json b/platform/commonUI/general/test/suite.json index 9f80aaabc2..0d19fbb9e4 100644 --- a/platform/commonUI/general/test/suite.json +++ b/platform/commonUI/general/test/suite.json @@ -17,8 +17,6 @@ "directives/MCTPopup", "directives/MCTResize", "directives/MCTScroll", - "services/DateAggregator", - "services/UTCDateProvider", "services/Popup", "services/PopupService", "services/UrlService",