From 0d6f013cd19b5be65f2ba601b97ddda06b5837dc Mon Sep 17 00:00:00 2001 From: hatim dinia Date: Mon, 4 Mar 2024 10:24:14 +0100 Subject: [PATCH] fix(results): adjust date times for accurate frequency display --- .../explore/Results/ResultDetails/index.tsx | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/webapp/src/components/App/Singlestudy/explore/Results/ResultDetails/index.tsx b/webapp/src/components/App/Singlestudy/explore/Results/ResultDetails/index.tsx index ab74bd3a83..e1c3748b73 100644 --- a/webapp/src/components/App/Singlestudy/explore/Results/ResultDetails/index.tsx +++ b/webapp/src/components/App/Singlestudy/explore/Results/ResultDetails/index.tsx @@ -153,11 +153,36 @@ function ResultDetails() { const dateTimeFromIndex = useMemo(() => { if (!matrixRes.data) return []; - return matrixRes.data.index.map((dateTime) => { - const parsedDate = moment(dateTime, "MM/DD HH:mm"); - return parsedDate.format("ddd D MMM HH:mm"); - }); - }, [matrixRes.data]); + // Annual format has a static string + if (timestep === Timestep.Annual) { + return ["Annual"]; + } + + // Original date/time format mapping for moment parsing + const parseFormat = { + [Timestep.Hourly]: "MM/DD HH:mm", + [Timestep.Daily]: "MM/DD", + [Timestep.Weekly]: "WW", + [Timestep.Monthly]: "MM", + }[timestep]; + + // Output formats for each timestep to match legacy UI requirements + const outputFormat = { + [Timestep.Hourly]: "DD MMM HH:mm I", + [Timestep.Daily]: "DD MMM I", + [Timestep.Weekly]: "WW", + [Timestep.Monthly]: "MMM", + }[timestep]; + + const needsIndex = + timestep === Timestep.Hourly || timestep === Timestep.Daily; + + return matrixRes.data.index.map((dateTime, i) => + moment(dateTime, parseFormat).format( + outputFormat.replace("I", needsIndex ? ` - ${i + 1}` : ""), + ), + ); + }, [matrixRes.data, timestep]); //////////////////////////////////////////////////////////////// // Event Handlers