diff options
Diffstat (limited to 'src/utils/helpers')
| -rw-r--r-- | src/utils/helpers/format.ts | 16 |
1 files changed, 16 insertions, 0 deletions
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); +}; |
