mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 15:43:48 +00:00
* Remove legacy bundles * Replace legacy format management with vanilla JS * Redefine legacy formats in plugins instead of bundles * Remove 'draft' from API documentation * Remove focus from test spec * Register local time system using new API * Fixed broken custom formatter test spec * Make capitalization consistent * Rewrite test for terse formatting for time conductor * Make dependency on UTCTimeFormat explicit Co-authored-by: John Hill <john.c.hill@nasa.gov>
38 lines
879 B
JavaScript
38 lines
879 B
JavaScript
|
|
import moment from 'moment';
|
|
|
|
const DATE_FORMAT = "HH:mm:ss";
|
|
const DATE_FORMATS = [
|
|
DATE_FORMAT
|
|
];
|
|
|
|
/**
|
|
* Formatter for duration. Uses moment to produce a date from a given
|
|
* value, but output is formatted to display only time. Can be used for
|
|
* specifying a time duration. For specifying duration, it's best to
|
|
* specify a date of January 1, 1970, as the ms offset will equal the
|
|
* duration represented by the time.
|
|
*
|
|
* @implements {Format}
|
|
* @constructor
|
|
* @memberof platform/commonUI/formats
|
|
*/
|
|
class DurationFormat {
|
|
constructor() {
|
|
this.key = "duration";
|
|
}
|
|
format(value) {
|
|
return moment.utc(value).format(DATE_FORMAT);
|
|
}
|
|
|
|
parse(text) {
|
|
return moment.duration(text).asMilliseconds();
|
|
}
|
|
|
|
validate(text) {
|
|
return moment.utc(text, DATE_FORMATS, true).isValid();
|
|
}
|
|
}
|
|
|
|
export default DurationFormat;
|