Commit 98e28980 authored by Yuri Mikhin's avatar Yuri Mikhin Committed by Yuri Mikhin

Remove date-fns.

parent 2d436427
import { Box, Button, Grid, Heading, Icon, IconButton, Menu, MenuButton, MenuItem, MenuList, Text, useColorModeValue, VisuallyHidden } from '@chakra-ui/react'; import { Box, Button, Grid, Heading, Icon, IconButton, Menu, MenuButton, MenuItem, MenuList, Text, useColorModeValue, VisuallyHidden } from '@chakra-ui/react';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { format, parse } from 'date-fns';
import React, { useCallback, useState } from 'react'; import React, { useCallback, useState } from 'react';
import type { Charts } from 'types/api/stats'; import type { Charts } from 'types/api/stats';
...@@ -23,7 +22,9 @@ type Props = { ...@@ -23,7 +22,9 @@ type Props = {
interval: StatsIntervalIds; interval: StatsIntervalIds;
} }
const dateFormat = 'dd-LL-yyyy'; function formatDate(date: Date) {
return date.toISOString().substring(0, 10);
}
const ChartWidget = ({ id, title, description, apiMethodURL, interval }: Props) => { const ChartWidget = ({ id, title, description, apiMethodURL, interval }: Props) => {
const fetch = useFetch(); const fetch = useFetch();
...@@ -33,8 +34,8 @@ const ChartWidget = ({ id, title, description, apiMethodURL, interval }: Props) ...@@ -33,8 +34,8 @@ const ChartWidget = ({ id, title, description, apiMethodURL, interval }: Props)
const [ isFullscreen, setIsFullscreen ] = useState(false); const [ isFullscreen, setIsFullscreen ] = useState(false);
const [ isZoomResetInitial, setIsZoomResetInitial ] = React.useState(true); const [ isZoomResetInitial, setIsZoomResetInitial ] = React.useState(true);
const endDate = selectedInterval.start ? format(new Date(), dateFormat) : undefined; const endDate = selectedInterval.start ? formatDate(new Date()) : undefined;
const startDate = selectedInterval.start ? format(selectedInterval.start, dateFormat) : undefined; const startDate = selectedInterval.start ? formatDate(selectedInterval.start) : undefined;
const menuButtonColor = useColorModeValue('black', 'white'); const menuButtonColor = useColorModeValue('black', 'white');
const borderColor = useColorModeValue('gray.200', 'gray.600'); const borderColor = useColorModeValue('gray.200', 'gray.600');
...@@ -77,7 +78,7 @@ const ChartWidget = ({ id, title, description, apiMethodURL, interval }: Props) ...@@ -77,7 +78,7 @@ const ChartWidget = ({ id, title, description, apiMethodURL, interval }: Props)
if (data) { if (data) {
const items = data.chart const items = data.chart
.map((item) => { .map((item) => {
return { date: parse(item.date, dateFormat, new Date()), value: Number(item.value) }; return { date: new Date(item.date), value: Number(item.value) };
}); });
return ( return (
......
import { sub } from 'date-fns';
import type { StatsSectionIds, StatsIntervalIds } from 'types/client/stats'; import type { StatsSectionIds, StatsIntervalIds } from 'types/client/stats';
export const STATS_SECTIONS: { [key in StatsSectionIds]?: string } = { export const STATS_SECTIONS: { [key in StatsSectionIds]?: string } = {
...@@ -33,5 +31,7 @@ export const STATS_INTERVALS: { [key in StatsIntervalIds]: { title: string; star ...@@ -33,5 +31,7 @@ export const STATS_INTERVALS: { [key in StatsIntervalIds]: { title: string; star
}; };
function getStartDateInPast(months: number): Date { function getStartDateInPast(months: number): Date {
return sub(new Date(), { months }); const date = new Date();
date.setMonth(date.getMonth() - months);
return date;
} }
...@@ -4735,11 +4735,6 @@ data-urls@^3.0.2: ...@@ -4735,11 +4735,6 @@ data-urls@^3.0.2:
whatwg-mimetype "^3.0.0" whatwg-mimetype "^3.0.0"
whatwg-url "^11.0.0" whatwg-url "^11.0.0"
date-fns@^2.29.3:
version "2.29.3"
resolved "https://registry.yarnpkg.com/date-fns/-/date-fns-2.29.3.tgz#27402d2fc67eb442b511b70bbdf98e6411cd68a8"
integrity sha512-dDCnyH2WnnKusqvZZ6+jA1O51Ibt8ZMRNkDZdyAyK4YfbDwa/cEmuztzG5pk6hqlp9aSBPYcjOlktquahGwGeA==
dateformat@^4.6.3: dateformat@^4.6.3:
version "4.6.3" version "4.6.3"
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-4.6.3.tgz#556fa6497e5217fedb78821424f8a1c22fa3f4b5" resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-4.6.3.tgz#556fa6497e5217fedb78821424f8a1c22fa3f4b5"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment