gitscope
← marzneshin / v0.6.2 / dashboard/src/common/stats-charts/utils/date-x-axies.ts
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/common/stats-charts/utils/date-x-axies.ts · TypeScript
Blame Raw
 1import { ChartDateInterval } from "../types";
 2
 3export const dateXAxisTicks = (value: string, timeRange: ChartDateInterval) => {
 4    const date = new Date(value);
 5    const format = {
 6        "90d": {
 7            day: "numeric",
 8            month: "short",
 9        },
10        "30d": {
11            day: "numeric",
12        },
13        "7d": {
14            day: "numeric",
15            hour: "numeric",
16        },
17        "1d": {
18            minute: "numeric",
19            hour: "numeric",
20        }
21    }[timeRange as ChartDateInterval];
22
23    if (timeRange === "1d") {
24        return date.toLocaleTimeString("en-US", format as Intl.DateTimeFormatOptions);
25    }
26
27    return date.toLocaleDateString("en-US", format as Intl.DateTimeFormatOptions);
28}