Merge pull request #771 from benphelps/datetime-locale

Feature: allow setting locale for datetime widget directly
pull/777/head
shamoon 2 years ago committed by GitHub
commit 1fd198c255
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -13,17 +13,18 @@ const textSizes = {
};
export default function DateTime({ options }) {
const { text_size: textSize, format } = options;
const { text_size: textSize, locale, format } = options;
const { i18n } = useTranslation();
const [date, setDate] = useState("");
const dateLocale = locale ?? i18n.language;
useEffect(() => {
const dateFormat = new Intl.DateTimeFormat(i18n.language, { ...format });
const dateFormat = new Intl.DateTimeFormat(dateLocale, { ...format });
const interval = setInterval(() => {
setDate(dateFormat.format(new Date()));
}, 1000);
return () => clearInterval(interval);
}, [date, setDate, i18n.language, format]);
}, [date, setDate, dateLocale, format]);
return (
<div className="flex flex-col justify-center first:ml-0 ml-4">

Loading…
Cancel
Save