diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-10-12 17:24:13 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:14:41 +0100 |
| commit | 00f147a7a687d5772bcc538bc606cfff972178cd (patch) | |
| tree | 27eabeb83c05e14162c51b69d4a6f36d461947fc /src/utils | |
| parent | c87c615b5866b8a8f361eeb0764bfdea85740e90 (diff) | |
feat(components): add a Time component
Instead of using helpers functions to format the date each time we need
to use a time element, it makes more sense to create a new component
dedicated to this task.
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/helpers/dates.ts | 40 | ||||
| -rw-r--r-- | src/utils/helpers/index.ts | 1 |
2 files changed, 0 insertions, 41 deletions
diff --git a/src/utils/helpers/dates.ts b/src/utils/helpers/dates.ts deleted file mode 100644 index 82c14db..0000000 --- a/src/utils/helpers/dates.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { settings } from '../config'; - -/** - * Format a date based on a locale. - * - * @param {string} date - The date. - * @param {string} [locale] - A locale. - * @returns {string} The locale date string. - */ -export const getFormattedDate = ( - date: string, - locale: string = settings.locales.defaultLocale -): string => { - const dateOptions: Intl.DateTimeFormatOptions = { - day: 'numeric', - month: 'long', - year: 'numeric', - }; - - return new Date(date).toLocaleDateString(locale, dateOptions); -}; - -/** - * Format a time based on a locale. - * - * @param {string} time - The time. - * @param {string} [locale] - A locale. - * @returns {string} The locale time string. - */ -export const getFormattedTime = ( - time: string, - locale: string = settings.locales.defaultLocale -): string => { - const formattedTime = new Date(time).toLocaleTimeString(locale, { - hour: 'numeric', - minute: 'numeric', - }); - - return locale === 'fr' ? formattedTime.replace(':', 'h') : formattedTime; -}; diff --git a/src/utils/helpers/index.ts b/src/utils/helpers/index.ts index 1a35583..b2a4534 100644 --- a/src/utils/helpers/index.ts +++ b/src/utils/helpers/index.ts @@ -1,5 +1,4 @@ export * from './author'; -export * from './dates'; export * from './images'; export * from './pages'; export * from './rss'; |
