Format date with Tz

This commit is contained in:
Daniel Cojocea
2024-09-14 12:42:31 -04:00
parent d8664d3ed7
commit 10dd595cbc
2 changed files with 8 additions and 8 deletions

View File

@@ -11,9 +11,9 @@ import {
import { Box, Stack, Typography } from "@mui/material";
import { useTheme } from "@emotion/react";
import { useMemo } from "react";
import "./index.css";
import { useSelector } from "react-redux";
import { formatDateWithTz } from "../../../Utils/timeUtils";
import "./index.css";
const CustomToolTip = ({ active, payload, label }) => {
const uiTimezone = useSelector((state) => state.ui.timezone);

View File

@@ -11,7 +11,8 @@ import {
import { useTheme } from "@emotion/react";
import { useMemo } from "react";
import { Box, Stack, Typography } from "@mui/material";
import { formatDate } from "../../../../Utils/timeUtils";
import { formatDateWithTz } from "../../../../Utils/timeUtils";
import { useSelector } from "react-redux";
const config = {
seo: {
@@ -47,6 +48,8 @@ const config = {
const CustomToolTip = ({ active, payload, label, config }) => {
const theme = useTheme();
const uiTimezone = useSelector((state) => state.ui.timezone);
if (active && payload && payload.length) {
return (
<Box
@@ -66,7 +69,7 @@ const CustomToolTip = ({ active, payload, label, config }) => {
fontWeight: 500,
}}
>
{formatDate(new Date(label))}
{formatDateWithTz(label, "ddd, MMMM D, YYYY, h:mm A", uiTimezone)}
</Typography>
{Object.keys(config)
.reverse()
@@ -175,6 +178,7 @@ const processDataWithGaps = (data, interval) => {
*/
const CustomTick = ({ x, y, payload, index }) => {
const theme = useTheme();
const uiTimezone = useSelector((state) => state.ui.timezone);
// Render nothing for the first tick
if (index === 0) return null;
@@ -188,11 +192,7 @@ const CustomTick = ({ x, y, payload, index }) => {
fontSize={11}
fontWeight={400}
>
{formatDate(new Date(payload.value), {
year: undefined,
month: undefined,
day: undefined,
})}
{formatDateWithTz(payload?.value, "h:mm a", uiTimezone)}
</Text>
);
};