Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC-32820 ECL Watch v9 logs view timestamp formatting #19205

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions esp/src/src-react/components/Logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -132,7 +132,17 @@ export const Logs: React.FunctionComponent<LogsProps> = ({
}
});
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 },
audience: { label: nlsHPCC.Audience, width: 60, sortable: false, },
Expand Down
23 changes: 23 additions & 0 deletions esp/src/src/Utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,29 @@ export function format(labelTpl, obj) {
.join("\n")
;
}

const TEN_TRILLION = 10000000000000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fyi I think JS supports const TEN_TRILLION = 10_000_000_000_000; now?

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;

Expand Down
Loading