mirror of
https://github.com/nasa/openmct.git
synced 2024-12-21 22:17:49 +00:00
4386 - In time conductor history, show them on hover if only milliseconds have changed (#4414)
Co-authored-by: Jamie V <jamie.j.vigliotta@nasa.gov> Co-authored-by: John Hill <john.c.hill@nasa.gov> Co-authored-by: Andrew Henry <akhenry@gmail.com> Co-authored-by: Shefali Joshi <simplyrender@gmail.com>
This commit is contained in:
parent
a584766618
commit
1d875cb8ca
@ -131,15 +131,15 @@ describe('time conductor', () => {
|
|||||||
describe('duration functions', () => {
|
describe('duration functions', () => {
|
||||||
it('should transform milliseconds to DHMS', () => {
|
it('should transform milliseconds to DHMS', () => {
|
||||||
const functionResults = [millisecondsToDHMS(0), millisecondsToDHMS(86400000),
|
const functionResults = [millisecondsToDHMS(0), millisecondsToDHMS(86400000),
|
||||||
millisecondsToDHMS(129600000), millisecondsToDHMS(661824000)];
|
millisecondsToDHMS(129600000), millisecondsToDHMS(661824000), millisecondsToDHMS(213927028)];
|
||||||
const validResults = [' ', '+ 1d', '+ 1d 12h', '+ 7d 15h 50m 24s'];
|
const validResults = [' ', '+ 1d', '+ 1d 12h', '+ 7d 15h 50m 24s', '+ 2d 11h 25m 27s 28ms'];
|
||||||
expect(validResults).toEqual(functionResults);
|
expect(validResults).toEqual(functionResults);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get precise duration', () => {
|
it('should get precise duration', () => {
|
||||||
const functionResults = [getPreciseDuration(0), getPreciseDuration(643680000),
|
const functionResults = [getPreciseDuration(0), getPreciseDuration(643680000),
|
||||||
getPreciseDuration(1605312000)];
|
getPreciseDuration(1605312000), getPreciseDuration(213927028)];
|
||||||
const validResults = ['00:00:00:00', '07:10:48:00', '18:13:55:12'];
|
const validResults = ['00:00:00:00:000', '07:10:48:00:000', '18:13:55:12:000', '02:11:25:27:028'];
|
||||||
expect(validResults).toEqual(functionResults);
|
expect(validResults).toEqual(functionResults);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -32,8 +32,16 @@ function normalizeAge(num) {
|
|||||||
return isWhole ? hundredtized / 100 : num;
|
return isWhole ? hundredtized / 100 : num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function padLeadingZeros(num, numOfLeadingZeros) {
|
||||||
|
return num.toString().padStart(numOfLeadingZeros, '0');
|
||||||
|
}
|
||||||
|
|
||||||
function toDoubleDigits(num) {
|
function toDoubleDigits(num) {
|
||||||
return num >= 10 ? num : `0${num}`;
|
return padLeadingZeros(num, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function toTripleDigits(num) {
|
||||||
|
return padLeadingZeros(num, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
function addTimeSuffix(value, suffix) {
|
function addTimeSuffix(value, suffix) {
|
||||||
@ -46,7 +54,8 @@ export function millisecondsToDHMS(numericDuration) {
|
|||||||
addTimeSuffix(Math.floor(normalizeAge(ms / ONE_DAY)), 'd'),
|
addTimeSuffix(Math.floor(normalizeAge(ms / ONE_DAY)), 'd'),
|
||||||
addTimeSuffix(Math.floor(normalizeAge((ms % ONE_DAY) / ONE_HOUR)), 'h'),
|
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_HOUR) / ONE_MINUTE)), 'm'),
|
||||||
addTimeSuffix(Math.floor(normalizeAge((ms % ONE_MINUTE) / ONE_SECOND)), 's')
|
addTimeSuffix(Math.floor(normalizeAge((ms % ONE_MINUTE) / ONE_SECOND)), 's'),
|
||||||
|
addTimeSuffix(Math.floor(normalizeAge(ms % ONE_SECOND)), "ms")
|
||||||
].filter(Boolean).join(' ');
|
].filter(Boolean).join(' ');
|
||||||
|
|
||||||
return `${ dhms ? '+' : ''} ${dhms}`;
|
return `${ dhms ? '+' : ''} ${dhms}`;
|
||||||
@ -59,7 +68,8 @@ export function getPreciseDuration(value) {
|
|||||||
toDoubleDigits(Math.floor(normalizeAge(ms / ONE_DAY))),
|
toDoubleDigits(Math.floor(normalizeAge(ms / ONE_DAY))),
|
||||||
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_DAY) / ONE_HOUR))),
|
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_DAY) / ONE_HOUR))),
|
||||||
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_HOUR) / ONE_MINUTE))),
|
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_HOUR) / ONE_MINUTE))),
|
||||||
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_MINUTE) / ONE_SECOND)))
|
toDoubleDigits(Math.floor(normalizeAge((ms % ONE_MINUTE) / ONE_SECOND))),
|
||||||
|
toTripleDigits(Math.floor(normalizeAge(ms % ONE_SECOND)))
|
||||||
].join(":");
|
].join(":");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user