Rework healthchecks date formatting

This commit is contained in:
shamoon 2023-02-19 23:30:45 -08:00
parent 5def5dd508
commit 594f47fa68

View File

@ -1,5 +1,7 @@
import { useTranslation } from "next-i18next"; import { useTranslation } from "next-i18next";
import { i18n } from "../../../next-i18next.config";
import Block from "components/services/widget/block"; import Block from "components/services/widget/block";
import Container from "components/services/widget/container"; import Container from "components/services/widget/container";
import useWidgetAPI from "utils/proxy/use-widget-api"; import useWidgetAPI from "utils/proxy/use-widget-api";
@ -7,22 +9,18 @@ import useWidgetAPI from "utils/proxy/use-widget-api";
function formatDate(dateString) { function formatDate(dateString) {
const date = new Date(dateString); const date = new Date(dateString);
const now = new Date(); const now = new Date();
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); let dateOptions = {
const diff = (now - date) / 1000; month: "numeric",
if (date > today && diff < 86400) {
return date.toLocaleTimeString([], {
hour: "numeric",
minute: "numeric",
});
}
return date.toLocaleDateString([], {
month: "short",
day: "numeric", day: "numeric",
hour: "numeric", hour: "numeric",
minute: "numeric", minute: "numeric",
}); };
if (date.getFullYear() === now.getFullYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate()) {
dateOptions = { timeStyle: "short" };
}
return new Intl.DateTimeFormat(i18n.language, dateOptions).format(date);
} }
export default function Component({ service }) { export default function Component({ service }) {