From f6e0e444820f67f212e362c54816df5d0e4d4cf0 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 25 Jan 2022 15:53:43 +0100 Subject: chore: wrap dates with time tag --- src/utils/helpers/format.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/utils/helpers/format.ts') diff --git a/src/utils/helpers/format.ts b/src/utils/helpers/format.ts index 2be1844..e45a6a0 100644 --- a/src/utils/helpers/format.ts +++ b/src/utils/helpers/format.ts @@ -267,3 +267,19 @@ export const getFormattedPost = (rawPost: RawArticle): Article => { return formattedPost; }; + +/** + * Converts a date to a string by using the specified locale. + * @param {string} date The date. + * @param {string} locale A locale. + * @returns {string} The formatted date to locale date string. + */ +export const getFormattedDate = (date: string, locale: string) => { + const dateOptions: Intl.DateTimeFormatOptions = { + day: 'numeric', + month: 'long', + year: 'numeric', + }; + + return new Date(date).toLocaleDateString(locale, dateOptions); +}; -- cgit v1.2.3