From 2d67b7982f910d6bc1846f3eca2ec217991eed7a Mon Sep 17 00:00:00 2001 From: julianedwards Date: Mon, 11 Sep 2023 13:08:17 -0400 Subject: [PATCH] EVG-20019: set log message timezone to user timezone and fix format (#2030) Co-authored-by: julianedwards --- src/hooks/index.ts | 1 + .../task/taskTabs/logs/logTypes/LogMessageLine.tsx | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 963024885d..d26fcedbd3 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -20,6 +20,7 @@ export { useTaskStatuses } from "./useTaskStatuses"; export { useUpsertQueryParams } from "./useUpsertQueryParams"; export { useSpruceConfig } from "./useSpruceConfig"; export { useUserSettings } from "./useUserSettings"; +export { useUserTimeZone } from "./useUserTimeZone"; export { useDateFormat } from "./useDateFormat"; export { useBreadcrumbRoot } from "./useBreadcrumbRoot"; export { useResize } from "./useResize"; diff --git a/src/pages/task/taskTabs/logs/logTypes/LogMessageLine.tsx b/src/pages/task/taskTabs/logs/logTypes/LogMessageLine.tsx index d19b84b951..db592b48a6 100644 --- a/src/pages/task/taskTabs/logs/logTypes/LogMessageLine.tsx +++ b/src/pages/task/taskTabs/logs/logTypes/LogMessageLine.tsx @@ -1,12 +1,13 @@ import { useMemo } from "react"; import AnsiUp from "ansi_up"; -import { format } from "date-fns"; +import { format, utcToZonedTime } from "date-fns-tz"; import parse from "html-react-parser"; import linkifyHtml from "linkify-html"; import { LogMessageFragment } from "gql/generated/types"; +import { useUserTimeZone } from "hooks"; import { getLogLineWrapper } from "./logMessageLine/LogLines"; -const FORMAT_STR = "yyyy/MM/d, HH:mm:ss.SSS"; +const FORMAT_STR = "yyyy/MM/dd HH:mm:ss.SSS"; const ansiUp = new AnsiUp(); export const LogMessageLine: React.FC = ({ @@ -14,7 +15,12 @@ export const LogMessageLine: React.FC = ({ severity, timestamp, }) => { - const time = timestamp ? `[${format(new Date(timestamp), FORMAT_STR)}] ` : ""; + const tz = useUserTimeZone(); + const time = timestamp + ? `[${format(new Date(utcToZonedTime(timestamp, tz)), FORMAT_STR, { + timeZone: tz, + })}] ` + : ""; const LogLineWrapper = getLogLineWrapper(severity); const memoizedLogLine = useMemo(() => { const render = linkifyHtml(ansiUp.ansi_to_html(message), {