Nanosecond-Precision Timestamps? #8058
-
Hello, Is it possible to visualize and ingest nanosecond-precision timestamps within MCT? If so, what would it take? A desire for greater-than-millisecond precision was also mentioned here by multiple users: #1788 Thank you so much, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Microsecond precision is broadly doable (although untested) because µs epoch values fit within a 64 bit JavaScript Number without a loss of precision. Here's a very basic implementation of a µs time system and formatter, that represent timestamps as ms since the JavaScript epoch, with a decimal component representing microseconds. eg. Be warned, this is largely untested, and while the API supports this, there may be bugs where we have made dumb assumptions in the code. If so, please let us know so we can fix them! /*
* Define a new time system that supports µs precision timestamps.
*/
openmct.install((openmct) => {
openmct.time.addTimeSystem({
key: 'µs',
name: 'microseconds',
cssClass: 'icon-clock',
timeFormat: 'µsf',
durationFormat: 'duration',
isUTCBased: true
});
});
/*
* Define a formatter that will parse and format µs precision timestamps
*/
openmct.install((openmct) => {
function getµsComponent(text) {
return text.substring(23, text.length - 1);
}
function getDecimalPart(floatOrInteger) {
return (floatOrInteger * 1000) - Math.floor(floatOrInteger) * 1000;
}
openmct.telemetry.addFormat({
key: 'µsf',
parse(text) {
if (typeof text === 'number' || text === undefined) {
return text;
} else {
if (!text.endsWith("Z")) {
throw new Error("Only supports Zulu timestamps");
}
const µsPart = getµsComponent(text).padEnd(3, '0');
const msPrecisionNumber = Date.parse(text);
const µsPrecisionNumber = msPrecisionNumber + (Number.parseInt(µsPart, 10) / 1000);
return µsPrecisionNumber;
}
},
format(number) {
if (typeof number === "number"){
let dateText = new Date(number).toISOString();
if (!Number.isInteger(number)) {
// Append microseconds to the end
dateText = dateText.substring(dateText.length - 2) + getDecimalPart(number).toString().padStart(3, '0') + 'Z';
}
return dateText;
} else {
return number;
}
}
})
}); Nanoseconds are a harder problem as JavaScript just can't represent them as a native |
Beta Was this translation helpful? Give feedback.
Microsecond precision is broadly doable (although untested) because µs epoch values fit within a 64 bit JavaScript Number without a loss of precision.
Here's a very basic implementation of a µs time system and formatter, that represent timestamps as ms since the JavaScript epoch, with a decimal component representing microseconds. eg.
1747774208841.123
would be formatted as2025-05-20T20:50:08.841123Z
Be warned, this is largely untested, and while the API supports this, there may be bugs where we have made dumb assumptions in the code. If so, please let us know so we can fix them!