mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 07:38:15 +00:00
@ -25,15 +25,14 @@ define([
|
|||||||
], function (
|
], function (
|
||||||
moment
|
moment
|
||||||
) {
|
) {
|
||||||
|
const DATE_FORMAT = "YYYY-MM-DD HH:mm:ss.SSS";
|
||||||
var DATE_FORMAT = "YYYY-MM-DD HH:mm:ss.SSS",
|
const DATE_FORMATS = [
|
||||||
DATE_FORMATS = [
|
DATE_FORMAT,
|
||||||
DATE_FORMAT,
|
DATE_FORMAT + "Z",
|
||||||
DATE_FORMAT + "Z",
|
"YYYY-MM-DD HH:mm:ss",
|
||||||
"YYYY-MM-DD HH:mm:ss",
|
"YYYY-MM-DD HH:mm",
|
||||||
"YYYY-MM-DD HH:mm",
|
"YYYY-MM-DD"
|
||||||
"YYYY-MM-DD"
|
];
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef Scale
|
* @typedef Scale
|
||||||
@ -53,15 +52,27 @@ define([
|
|||||||
this.key = "utc";
|
this.key = "utc";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} formatString
|
||||||
|
* @returns the value of formatString if the value is a string type and exists in the DATE_FORMATS array; otherwise the DATE_FORMAT value.
|
||||||
|
*/
|
||||||
|
function validateFormatString(formatString) {
|
||||||
|
return typeof formatString === 'string' && DATE_FORMATS.includes(formatString) ? formatString : DATE_FORMAT;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number} value The value to format.
|
* @param {number} value The value to format.
|
||||||
* @returns {string} the formatted date(s). If multiple values were requested, then an array of
|
* @param {string} formatString The string format to format. Default "YYYY-MM-DD HH:mm:ss.SSS" + "Z"
|
||||||
|
* @returns {string} the formatted date(s) according to the proper parameter of formatString or the default value of "YYYY-MM-DD HH:mm:ss.SSS" + "Z".
|
||||||
|
* If multiple values were requested, then an array of
|
||||||
* formatted values will be returned. Where a value could not be formatted, `undefined` will be returned at its position
|
* formatted values will be returned. Where a value could not be formatted, `undefined` will be returned at its position
|
||||||
* in the array.
|
* in the array.
|
||||||
*/
|
*/
|
||||||
UTCTimeFormat.prototype.format = function (value) {
|
UTCTimeFormat.prototype.format = function (value, formatString) {
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
return moment.utc(value).format(DATE_FORMAT) + "Z";
|
const format = validateFormatString(formatString);
|
||||||
|
|
||||||
|
return moment.utc(value).format(format) + (formatString ? '' : 'Z');
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ const LOCAL_STORAGE_HISTORY_KEY_FIXED = 'tcHistory';
|
|||||||
const LOCAL_STORAGE_HISTORY_KEY_REALTIME = 'tcHistoryRealtime';
|
const LOCAL_STORAGE_HISTORY_KEY_REALTIME = 'tcHistoryRealtime';
|
||||||
const DEFAULT_RECORDS = 10;
|
const DEFAULT_RECORDS = 10;
|
||||||
|
|
||||||
import { getDuration } from "utils/duration";
|
import { millisecondsToDHMS } from "utils/duration";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
inject: ['openmct', 'configuration'],
|
inject: ['openmct', 'configuration'],
|
||||||
@ -142,7 +142,7 @@ export default {
|
|||||||
let description = `${startTime} - ${this.formatTime(timespan.end)}`;
|
let description = `${startTime} - ${this.formatTime(timespan.end)}`;
|
||||||
|
|
||||||
if (this.timeSystem.isUTCBased && !this.openmct.time.clock()) {
|
if (this.timeSystem.isUTCBased && !this.openmct.time.clock()) {
|
||||||
name = `${startTime} ${getDuration(timespan.end - timespan.start)}`;
|
name = `${startTime} ${millisecondsToDHMS(timespan.end - timespan.start)}`;
|
||||||
} else {
|
} else {
|
||||||
name = description;
|
name = description;
|
||||||
}
|
}
|
||||||
@ -263,7 +263,7 @@ export default {
|
|||||||
format: format
|
format: format
|
||||||
}).formatter;
|
}).formatter;
|
||||||
|
|
||||||
return (isNegativeOffset ? '-' : '') + formatter.format(time);
|
return (isNegativeOffset ? '-' : '') + formatter.format(time, 'YYYY-MM-DD HH:mm:ss');
|
||||||
},
|
},
|
||||||
showHistoryMenu() {
|
showHistoryMenu() {
|
||||||
const elementBoundingClientRect = this.$refs.historyButton.getBoundingClientRect();
|
const elementBoundingClientRect = this.$refs.historyButton.getBoundingClientRect();
|
||||||
|
@ -20,7 +20,8 @@
|
|||||||
* at runtime from the About dialog for additional information.
|
* at runtime from the About dialog for additional information.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
const ONE_MINUTE = 60 * 1000;
|
const ONE_SECOND = 1000;
|
||||||
|
const ONE_MINUTE = 60 * ONE_SECOND;
|
||||||
const ONE_HOUR = ONE_MINUTE * 60;
|
const ONE_HOUR = ONE_MINUTE * 60;
|
||||||
const ONE_DAY = ONE_HOUR * 24;
|
const ONE_DAY = ONE_HOUR * 24;
|
||||||
|
|
||||||
@ -39,34 +40,20 @@ function toDoubleDigits(num) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDuration(numericDuration) {
|
function addTimeSuffix(value, suffix) {
|
||||||
let result;
|
return typeof value === 'number' && value > 0 ? `${value + suffix}` : '';
|
||||||
let age;
|
}
|
||||||
|
|
||||||
if (numericDuration > ONE_DAY - 1) {
|
export function millisecondsToDHMS(numericDuration) {
|
||||||
age = normalizeAge((numericDuration / ONE_DAY)).toFixed(2);
|
const ms = numericDuration || 0;
|
||||||
result = `+ ${age} day`;
|
const dhms = [
|
||||||
|
addTimeSuffix(Math.floor(normalizeAge(ms / ONE_DAY)), 'd'),
|
||||||
|
addTimeSuffix(Math.floor(normalizeAge((ms % ONE_DAY) / ONE_HOUR)), 'h'),
|
||||||
|
addTimeSuffix(Math.floor(normalizeAge((ms % ONE_HOUR) / ONE_MINUTE)), 'm'),
|
||||||
|
addTimeSuffix(Math.floor(normalizeAge((ms % ONE_MINUTE) / ONE_SECOND)), 's')
|
||||||
|
].filter(Boolean).join(' ');
|
||||||
|
|
||||||
if (age !== 1) {
|
return `${ dhms ? '+' : ''} ${dhms}`;
|
||||||
result += 's';
|
|
||||||
}
|
|
||||||
} else if (numericDuration > ONE_HOUR - 1) {
|
|
||||||
age = normalizeAge((numericDuration / ONE_HOUR).toFixed(2));
|
|
||||||
result = `+ ${age} hour`;
|
|
||||||
|
|
||||||
if (age !== 1) {
|
|
||||||
result += 's';
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
age = normalizeAge((numericDuration / ONE_MINUTE).toFixed(2));
|
|
||||||
result = `+ ${age} min`;
|
|
||||||
|
|
||||||
if (age !== 1) {
|
|
||||||
result += 's';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPreciseDuration(numericDuration) {
|
export function getPreciseDuration(numericDuration) {
|
||||||
|
Reference in New Issue
Block a user