2022-09-16 10:53:12 +03:00
|
|
|
import { useState, useEffect } from "react";
|
2022-09-25 19:43:00 +03:00
|
|
|
import { useTranslation } from "next-i18next";
|
2023-06-03 01:10:15 +01:00
|
|
|
|
|
|
|
import Container from "../widget/container";
|
|
|
|
import Raw from "../widget/raw";
|
2022-09-16 10:53:12 +03:00
|
|
|
|
|
|
|
const textSizes = {
|
|
|
|
"4xl": "text-4xl",
|
|
|
|
"3xl": "text-3xl",
|
|
|
|
"2xl": "text-2xl",
|
|
|
|
xl: "text-xl",
|
|
|
|
lg: "text-lg",
|
|
|
|
md: "text-md",
|
|
|
|
sm: "text-sm",
|
|
|
|
xs: "text-xs",
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function DateTime({ options }) {
|
2023-01-04 13:53:06 -08:00
|
|
|
const { text_size: textSize, locale, format } = options;
|
2022-09-16 10:53:12 +03:00
|
|
|
const { i18n } = useTranslation();
|
2022-11-28 10:42:21 -08:00
|
|
|
const [date, setDate] = useState("");
|
2023-01-04 13:53:06 -08:00
|
|
|
const dateLocale = locale ?? i18n.language;
|
2023-04-16 00:05:50 +01:00
|
|
|
|
2022-09-16 10:53:12 +03:00
|
|
|
useEffect(() => {
|
2023-01-04 13:53:06 -08:00
|
|
|
const dateFormat = new Intl.DateTimeFormat(dateLocale, { ...format });
|
2022-09-16 10:53:12 +03:00
|
|
|
const interval = setInterval(() => {
|
2022-11-28 10:42:21 -08:00
|
|
|
setDate(dateFormat.format(new Date()));
|
2022-09-16 10:53:12 +03:00
|
|
|
}, 1000);
|
|
|
|
return () => clearInterval(interval);
|
2023-01-04 13:53:06 -08:00
|
|
|
}, [date, setDate, dateLocale, format]);
|
2022-09-16 10:53:12 +03:00
|
|
|
|
|
|
|
return (
|
2023-06-03 01:10:15 +01:00
|
|
|
<Container options={options}>
|
|
|
|
<Raw>
|
|
|
|
<div className="flex flex-row items-center grow justify-end">
|
|
|
|
<span className={`text-theme-800 dark:text-theme-200 tabular-nums ${textSizes[textSize || "lg"]}`}>
|
|
|
|
{date}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</Raw>
|
|
|
|
</Container>
|
2022-09-16 10:53:12 +03:00
|
|
|
);
|
|
|
|
}
|