diff --git a/esp/src/src-react/components/Logs.tsx b/esp/src/src-react/components/Logs.tsx index a1fad7bab0d..5e697c77b55 100644 --- a/esp/src/src-react/components/Logs.tsx +++ b/esp/src/src-react/components/Logs.tsx @@ -3,7 +3,7 @@ import { CommandBar, ContextualMenuItemType, ICommandBarItemProps } from "@fluen import { GetLogsExRequest, LogaccessService, LogType, TargetAudience, WsLogaccess } from "@hpcc-js/comms"; import { Level, scopedLogger } from "@hpcc-js/util"; import nlsHPCC from "src/nlsHPCC"; -import { logColor, removeAllExcept, wuidToDate, wuidToTime } from "src/Utility"; +import { formatDateString, logColor, removeAllExcept, timestampToDate, wuidToDate, wuidToTime } from "src/Utility"; import { useLogAccessInfo } from "../hooks/platform"; import { HolyGrail } from "../layouts/HolyGrail"; import { pushParams } from "../util/history"; @@ -133,7 +133,17 @@ export const Logs: React.FunctionComponent = ({ } }); const retVal = { - timestamp: { label: nlsHPCC.TimeStamp, width: 140, sortable: false, }, + timestamp: { + label: nlsHPCC.TimeStamp, width: 140, sortable: false, + formatter: ts => { + if (ts) { + if (ts.indexOf(":") < 0) { + return timestampToDate(ts).toISOString(); + } + return formatDateString(ts); + } + }, + }, message: { label: nlsHPCC.Message, width: 600, sortable: false, }, components: { label: nlsHPCC.ContainerName, width: 150, sortable: false }, instance: { label: nlsHPCC.PodName, width: 150, sortable: false }, diff --git a/esp/src/src/Utility.ts b/esp/src/src/Utility.ts index 32c0a912f59..d17b93257cb 100644 --- a/esp/src/src/Utility.ts +++ b/esp/src/src/Utility.ts @@ -1242,6 +1242,29 @@ export function format(labelTpl, obj) { .join("\n") ; } + +const TEN_TRILLION = 10000000000000; +export function nanosToMillis(timestamp: number): number { + if (timestamp > TEN_TRILLION) { + return Math.round(timestamp / 1000000); + } else { + return timestamp; + } +} + +export function timestampToDate(timestamp: number): Date { + const millis = nanosToMillis(timestamp); + return new Date(millis); +} + +export function formatDateString(dateStr: string): string { + const matches = dateStr.match(/([0-9]{4}(?:-[0-9]{1,2})+)([T\s])((?:[0-9]{1,2}:)+[0-9]{1,2}\.[0-9]{1,3})(Z*)/); + if (matches) { + return `${matches[1]}T${matches[3]}${matches[4] ? matches[4] : "Z"}`; + } + return dateStr; +} + const theme = getTheme(); const { semanticColors } = theme;