diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-01-25 15:53:43 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-01-25 16:28:39 +0100 |
| commit | f6e0e444820f67f212e362c54816df5d0e4d4cf0 (patch) | |
| tree | 0f4fc539e66815b8f2ff1ad7d56a99e5aafa65cc /src/utils | |
| parent | 97dc68e22e754d8e478beee590dbe9868171af50 (diff) | |
chore: wrap dates with time tag
Diffstat (limited to 'src/utils')
| -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); +}; |
