modify date format to ISO standard, remove toTimeStamp method

This commit is contained in:
Alex Holliday committed 2025-01-01 17:27:12 -08:00
1 parent e7cf127fde
commit b332bed14e
5 files changed
+11 -39

No files matched your search

@@ -12,12 +12,11 @@ import { Box, Stack, Typography } from "@mui/material";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { useMemo, useState } from "react"; import { useMemo, useState } from "react";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { formatDateWithTz, toTimeStamp } from "../../../Utils/timeUtils"; import { formatDateWithTz } from "../../../Utils/timeUtils";
import "./index.css"; import "./index.css";
const CustomToolTip = ({ active, payload, label }) => { const CustomToolTip = ({ active, payload, label }) => {
const uiTimezone = useSelector((state) => state.ui.timezone); const uiTimezone = useSelector((state) => state.ui.timezone);
const dateFormat = label?.length === 10 ? "YYYY-MM-DD" : "YYYY-MM-DD-HH";
const theme = useTheme(); const theme = useTheme();
if (active && payload && payload.length) { if (active && payload && payload.length) {
const responseTime = payload[0]?.payload?.originalAvgResponseTime const responseTime = payload[0]?.payload?.originalAvgResponseTime
@@ -42,11 +41,7 @@ const CustomToolTip = ({ active, payload, label }) => {
fontWeight: 500, fontWeight: 500,
}} }}
> >
{formatDateWithTz( {formatDateWithTz(label, "ddd, MMMM D, YYYY, h:mm A", uiTimezone)}
toTimeStamp(label, dateFormat),
"ddd, MMMM D, YYYY, h:mm A",
uiTimezone
)}
</Typography> </Typography>
<Box mt={theme.spacing(1)}> <Box mt={theme.spacing(1)}>
<Box <Box
@@ -112,7 +107,6 @@ const CustomTick = ({ x, y, payload, index }) => {
const theme = useTheme(); const theme = useTheme();
const uiTimezone = useSelector((state) => state.ui.timezone); const uiTimezone = useSelector((state) => state.ui.timezone);
const dateFormat = payload?.value.length === 10 ? "YYYY-MM-DD" : "YYYY-MM-DD-HH";
// Render nothing for the first tick // Render nothing for the first tick
if (index === 0) return null; if (index === 0) return null;
return ( return (
@@ -124,7 +118,7 @@ const CustomTick = ({ x, y, payload, index }) => {
fontSize={11} fontSize={11}
fontWeight={400} fontWeight={400}
> >
{formatDateWithTz(toTimeStamp(payload?.value, dateFormat), "h:mm a", uiTimezone)} {formatDateWithTz(payload?.value, "h:mm a", uiTimezone)}
</Text> </Text>
); );
}; };
@@ -1,10 +1,9 @@
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { formatDateWithTz, toTimeStamp } from "../../../../Utils/timeUtils"; import { formatDateWithTz } from "../../../../Utils/timeUtils";
const CustomLabels = ({ x, width, height, firstDataPoint, lastDataPoint, type }) => { const CustomLabels = ({ x, width, height, firstDataPoint, lastDataPoint, type }) => {
const uiTimezone = useSelector((state) => state.ui.timezone); const uiTimezone = useSelector((state) => state.ui.timezone);
const formatString = type === "month" ? "YYYY-MM-DD" : "YYYY-MM-DD-HH";
const dateFormat = type === "day" ? "MMM D, h:mm A" : "MMM D"; const dateFormat = type === "day" ? "MMM D, h:mm A" : "MMM D";
return ( return (
@@ -16,11 +15,7 @@ const CustomLabels = ({ x, width, height, firstDataPoint, lastDataPoint, type })
textAnchor="start" textAnchor="start"
fontSize={11} fontSize={11}
> >
{formatDateWithTz( {formatDateWithTz(firstDataPoint._id, dateFormat, uiTimezone)}
toTimeStamp(firstDataPoint._id, formatString),
dateFormat,
uiTimezone
)}
</text> </text>
<text <text
x={width} x={width}
@@ -29,11 +24,7 @@ const CustomLabels = ({ x, width, height, firstDataPoint, lastDataPoint, type })
textAnchor="end" textAnchor="end"
fontSize={11} fontSize={11}
> >
{formatDateWithTz( {formatDateWithTz(lastDataPoint._id, dateFormat, uiTimezone)}
toTimeStamp(lastDataPoint._id, formatString),
dateFormat,
uiTimezone
)}
</text> </text>
</> </>
); );
+2 -9
View File
@@ -24,7 +24,6 @@ import { formatDateWithTz, formatDurationSplit } from "../../../Utils/timeUtils"
import { useIsAdmin } from "../../../Hooks/useIsAdmin"; import { useIsAdmin } from "../../../Hooks/useIsAdmin";
import IconBox from "../../../Components/IconBox"; import IconBox from "../../../Components/IconBox";
import StatBox from "../../../Components/StatBox"; import StatBox from "../../../Components/StatBox";
import { toTimeStamp } from "../../../Utils/timeUtils";
import UpBarChart from "./Charts/UpBarChart"; import UpBarChart from "./Charts/UpBarChart";
import DownBarChart from "./Charts/DownBarChart"; import DownBarChart from "./Charts/DownBarChart";
import ResponseGaugeChart from "./Charts/ResponseGaugeChart"; import ResponseGaugeChart from "./Charts/ResponseGaugeChart";
@@ -320,10 +319,7 @@ const DetailsPage = () => {
color={theme.palette.text.tertiary} color={theme.palette.text.tertiary}
> >
{formatDateWithTz( {formatDateWithTz(
toTimeStamp( hoveredUptimeData._id,
hoveredUptimeData._id,
dateRange === "month" ? "YYYY-MM-DD" : "YYYY-MM-DD-HH"
),
dateFormat, dateFormat,
uiTimezone uiTimezone
)} )}
@@ -380,10 +376,7 @@ const DetailsPage = () => {
color={theme.palette.text.tertiary} color={theme.palette.text.tertiary}
> >
{formatDateWithTz( {formatDateWithTz(
toTimeStamp( hoveredIncidentsData._id,
hoveredIncidentsData._id,
dateRange === "month" ? "YYYY-MM-DD" : "YYYY-MM-DD-HH"
),
dateFormat, dateFormat,
uiTimezone uiTimezone
)} )}
-6
View File
@@ -75,12 +75,6 @@ export const formatDurationSplit = (ms) => {
: { time: 0, format: "seconds" }; : { time: 0, format: "seconds" };
}; };
export const toTimeStamp = (date, format) => {
const dayJsDate = dayjs.utc(date, format);
const timestamp = dayJsDate.valueOf();
return timestamp;
};
export const formatDate = (date, customOptions) => { export const formatDate = (date, customOptions) => {
const options = { const options = {
year: "numeric", year: "numeric",
+3 -3
View File
@@ -323,9 +323,9 @@ const getUptimeDetailsById = async (req) => {
const { dateRange, normalize } = req.query; const { dateRange, normalize } = req.query;
const dates = getDateRange(dateRange); const dates = getDateRange(dateRange);
const formatLookup = { const formatLookup = {
day: "%Y-%m-%d-%H", day: "%Y-%m-%dT%H:00:00Z",
week: "%Y-%m-%d-%H", week: "%Y-%m-%dT%H:00:00Z",
month: "%Y-%m-%d", month: "%Y-%m-%dT00:00:00Z",
}; };
const dateString = formatLookup[dateRange]; const dateString = formatLookup[dateRange];