Skip to content

Commit

Permalink
fix(results): adjust date times for accurate frequency display
Browse files Browse the repository at this point in the history
  • Loading branch information
hdinia committed Mar 4, 2024
1 parent 8f35093 commit 0d6f013
Showing 1 changed file with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0d6f013

Please sign in to comment.