From f6e0e444820f67f212e362c54816df5d0e4d4cf0 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Tue, 25 Jan 2022 15:53:43 +0100
Subject: chore: wrap dates with time tag

---
 src/components/Widgets/RecentPosts/RecentPosts.tsx | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

(limited to 'src/components/Widgets/RecentPosts/RecentPosts.tsx')

diff --git a/src/components/Widgets/RecentPosts/RecentPosts.tsx b/src/components/Widgets/RecentPosts/RecentPosts.tsx
index 9c13aa2..8022bff 100644
--- a/src/components/Widgets/RecentPosts/RecentPosts.tsx
+++ b/src/components/Widgets/RecentPosts/RecentPosts.tsx
@@ -1,7 +1,9 @@
 import Spinner from '@components/Spinner/Spinner';
+import { config } from '@config/website';
 import { t } from '@lingui/macro';
 import { getPublishedPosts } from '@services/graphql/queries';
 import { ArticlePreview } from '@ts/types/articles';
+import { getFormattedDate } from '@utils/helpers/format';
 import Image from 'next/image';
 import Link from 'next/link';
 import { useRouter } from 'next/router';
@@ -12,12 +14,8 @@ const RecentPosts = () => {
   const { data, error } = useSWR('/recent-posts', () =>
     getPublishedPosts({ first: 3 })
   );
-  const { locale } = useRouter();
-  const dateOptions: Intl.DateTimeFormatOptions = {
-    day: 'numeric',
-    month: 'long',
-    year: 'numeric',
-  };
+  const router = useRouter();
+  const locale = router.locale ? router.locale : config.locales.defaultLocale;
 
   const getPost = (post: ArticlePreview) => {
     return (
@@ -40,10 +38,9 @@ const RecentPosts = () => {
               <dl className={styles.meta}>
                 <dt>{t`Published on:`}</dt>
                 <dd>
-                  {new Date(post.dates.publication).toLocaleDateString(
-                    locale,
-                    dateOptions
-                  )}
+                  <time dateTime={post.dates.publication}>
+                    {getFormattedDate(post.dates.publication, locale)}
+                  </time>
                 </dd>
               </dl>
             </article>
-- 
cgit v1.2.3

