2022-03-02 16:44:11 +00:00
|
|
|
import dayjs from 'dayjs';
|
|
|
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
2022-03-11 07:43:20 +00:00
|
|
|
import { useRouter } from 'next/router';
|
2022-03-02 16:44:11 +00:00
|
|
|
import { useEffect } from 'react';
|
|
|
|
|
2022-04-30 10:58:17 +00:00
|
|
|
const DateWrapper: React.FC<React.PropsWithChildren<unknown>> = ({ children }) => {
|
2022-03-11 07:43:20 +00:00
|
|
|
const { locale } = useRouter();
|
|
|
|
|
2022-03-02 16:44:11 +00:00
|
|
|
useEffect(() => {
|
|
|
|
dayjs.extend(relativeTime);
|
2022-03-10 14:32:46 +00:00
|
|
|
|
|
|
|
// Locales
|
2022-03-17 13:05:13 +00:00
|
|
|
require('dayjs/locale/ar');
|
2022-03-14 05:40:16 +00:00
|
|
|
require('dayjs/locale/bn');
|
2022-04-30 10:58:17 +00:00
|
|
|
require('dayjs/locale/cs');
|
2022-03-17 13:05:13 +00:00
|
|
|
require('dayjs/locale/da');
|
2022-03-11 18:42:07 +00:00
|
|
|
require('dayjs/locale/de');
|
2022-04-30 10:58:17 +00:00
|
|
|
require('dayjs/locale/el');
|
2022-03-14 05:40:16 +00:00
|
|
|
require('dayjs/locale/en');
|
|
|
|
require('dayjs/locale/es');
|
|
|
|
require('dayjs/locale/fr');
|
2022-03-11 19:21:35 +00:00
|
|
|
require('dayjs/locale/hi');
|
2022-03-14 05:40:16 +00:00
|
|
|
require('dayjs/locale/it');
|
2022-03-10 14:32:46 +00:00
|
|
|
require('dayjs/locale/kn');
|
2022-03-18 08:27:04 +00:00
|
|
|
require('dayjs/locale/ml');
|
2022-03-21 07:57:47 +00:00
|
|
|
require('dayjs/locale/nl');
|
2022-03-17 13:05:13 +00:00
|
|
|
require('dayjs/locale/pl');
|
2022-03-24 10:57:16 +00:00
|
|
|
require('dayjs/locale/pt');
|
2022-03-21 07:57:47 +00:00
|
|
|
require('dayjs/locale/ru');
|
2022-04-30 10:58:17 +00:00
|
|
|
require('dayjs/locale/sv');
|
2022-03-11 18:42:07 +00:00
|
|
|
require('dayjs/locale/ta');
|
2022-03-17 13:05:13 +00:00
|
|
|
require('dayjs/locale/tr');
|
2022-03-18 09:52:06 +00:00
|
|
|
require('dayjs/locale/vi');
|
2022-03-14 08:23:01 +00:00
|
|
|
require('dayjs/locale/zh');
|
2022-03-11 07:43:20 +00:00
|
|
|
|
|
|
|
locale && dayjs.locale(locale);
|
|
|
|
}, [locale]);
|
2022-03-02 16:44:11 +00:00
|
|
|
|
|
|
|
return <>{children}</>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DateWrapper;
|