diff --git a/src/common/util/date.ts b/src/common/util/date.ts index 77fd65e99..29562cecf 100644 --- a/src/common/util/date.ts +++ b/src/common/util/date.ts @@ -3,12 +3,10 @@ import { bg, enUS } from 'date-fns/locale' export const formatDate = 'dd MMM yyyy' export const formatDatetime = 'dd MMM yyyy HH:mm:ss' +export const dateViewFormat = 'dd.MM.yyyy' -export const formatDateString = (dateString: string | Date, language?: string) => { - if (language) { - return Intl.DateTimeFormat(language).format(new Date(dateString)) - } - return new Date(dateString).toLocaleDateString() +export const formatDateString = (dateString: string | Date) => { + return format(new Date(dateString), 'dd.MM.yyyy') } const matchLocale = (language?: string): Locale => { diff --git a/src/components/admin/modal/DetailsModal.tsx b/src/components/admin/modal/DetailsModal.tsx index 0d96cc5b1..02857c212 100644 --- a/src/components/admin/modal/DetailsModal.tsx +++ b/src/components/admin/modal/DetailsModal.tsx @@ -47,7 +47,7 @@ function DetailsModal() { - {formatDateString(row.row.createdAt, i18n?.language)} + {formatDateString(row.row.createdAt)} {row.row.message || row.row.comment} diff --git a/src/components/client/auth/profile/PersonalInfoTab.tsx b/src/components/client/auth/profile/PersonalInfoTab.tsx index e2c553d97..6fea01b9a 100644 --- a/src/components/client/auth/profile/PersonalInfoTab.tsx +++ b/src/components/client/auth/profile/PersonalInfoTab.tsx @@ -203,7 +203,7 @@ export default function PersonalInfoTab() {

{t('profile:personalInfo.birthday')}

{person?.birthday - ? formatDateString(person?.birthday, i18n?.language) + ? formatDateString(person?.birthday) : t('profile:personalInfo.noBirthday')} diff --git a/src/components/client/blog/DateCreated.tsx b/src/components/client/blog/DateCreated.tsx index 4a6d9c8e0..f97ec74de 100644 --- a/src/components/client/blog/DateCreated.tsx +++ b/src/components/client/blog/DateCreated.tsx @@ -13,7 +13,7 @@ export default function DateCreated({ createdAt, showLabel = false }: Props) { if (!createdAt) return null return ( - {showLabel && t('blog:created-on')} {formatDateString(createdAt, i18n?.language)} + {showLabel && t('blog:created-on')} {formatDateString(createdAt)} ) } diff --git a/src/components/client/campaign-news/CampaignNewsList.tsx b/src/components/client/campaign-news/CampaignNewsList.tsx index a1d5da083..297c8163d 100644 --- a/src/components/client/campaign-news/CampaignNewsList.tsx +++ b/src/components/client/campaign-news/CampaignNewsList.tsx @@ -111,7 +111,7 @@ export default function CampaignNewsList({ articles }: Props) { - {formatDateString(article.publishedAt, i18n?.language)}   + {formatDateString(article.publishedAt)}   {dateToTime(article.publishedAt, i18n?.language)} diff --git a/src/components/client/campaign-news/SingleArticlePage.tsx b/src/components/client/campaign-news/SingleArticlePage.tsx index 287d89e05..ff707c4c1 100644 --- a/src/components/client/campaign-news/SingleArticlePage.tsx +++ b/src/components/client/campaign-news/SingleArticlePage.tsx @@ -96,7 +96,7 @@ export default function SingleArticlePage({ slug }: Props) { - {formatDateString(article.publishedAt, i18n?.language)} + {formatDateString(article.publishedAt)} diff --git a/src/components/client/campaign-news/secured/NewsAdminPage.tsx b/src/components/client/campaign-news/secured/NewsAdminPage.tsx index 8b8970413..52896d24c 100644 --- a/src/components/client/campaign-news/secured/NewsAdminPage.tsx +++ b/src/components/client/campaign-news/secured/NewsAdminPage.tsx @@ -87,7 +87,7 @@ export function NewsAdminPage({ slug, isAdmin }: Props) { flex: 1, minWidth: 140, renderCell: (params: GridRenderCellParams): React.ReactNode => { - return formatDateString(params.row.createdAt, i18n?.language) + return formatDateString(params.row.createdAt) }, }, { @@ -99,7 +99,7 @@ export function NewsAdminPage({ slug, isAdmin }: Props) { minWidth: 200, renderCell: (params: GridRenderCellParams): React.ReactNode => { const date: Date = params.row.publishedAt - return date ? formatDateString(date, i18n?.language) : '' + return date ? formatDateString(date) : '' }, }, { @@ -107,7 +107,7 @@ export function NewsAdminPage({ slug, isAdmin }: Props) { headerName: t('article.lastEdit'), headerClassName: classes.gridColumn, renderCell: (params: GridRenderCellParams): React.ReactNode => { - return params.row.editedAt ? formatDateString(params.row.editedAt, i18n?.language) : '' + return params.row.editedAt ? formatDateString(params.row.editedAt) : '' }, minWidth: 200, flex: 1, diff --git a/src/components/client/campaigns/CampaignNewsSection.tsx b/src/components/client/campaigns/CampaignNewsSection.tsx index 7d7c00dfc..e310c0c5a 100644 --- a/src/components/client/campaigns/CampaignNewsSection.tsx +++ b/src/components/client/campaigns/CampaignNewsSection.tsx @@ -199,7 +199,7 @@ export default function CampaignNewsSection({ campaign, canCreateArticle }: Prop - {`${formatDateString(article.publishedAt, i18n?.language)} ${dateToTime( + {`${formatDateString(article.publishedAt)} ${dateToTime( article.publishedAt, i18n?.language, )}`} @@ -228,7 +228,7 @@ export default function CampaignNewsSection({ campaign, canCreateArticle }: Prop - {`${formatDateString(article.publishedAt, i18n?.language)} ${dateToTime( + {`${formatDateString(article.publishedAt)} ${dateToTime( article.publishedAt, i18n?.language, )}`} diff --git a/src/components/common/form/FormDatePicker.tsx b/src/components/common/form/FormDatePicker.tsx index dad77eb72..47c4dbfd0 100644 --- a/src/components/common/form/FormDatePicker.tsx +++ b/src/components/common/form/FormDatePicker.tsx @@ -2,9 +2,8 @@ import { LocalizationProvider, DatePicker } from '@mui/x-date-pickers' import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns' import { format } from 'date-fns' import { useField, useFormikContext } from 'formik' -import { useTranslation } from 'next-i18next' -import { DATE_VALUE_FORMAT, getDateFormat } from 'common/util/date' +import { DATE_VALUE_FORMAT, dateViewFormat } from 'common/util/date' /** * MUI date picker to be connected with Formik. Propagates updates to the passed Formik field name @@ -15,9 +14,6 @@ import { DATE_VALUE_FORMAT, getDateFormat } from 'common/util/date' export default function FormDatePicker({ name, label }: { name: string; label: string }) { const [field] = useField(name) const { setFieldValue } = useFormikContext() - const { i18n } = useTranslation() - - const dateViewFormat = getDateFormat(i18n?.language) const updateValue = (newValue: Date | null) => { let formattedValue diff --git a/src/components/common/person/PersonInfo.tsx b/src/components/common/person/PersonInfo.tsx index cf197a0c5..8f4a7105b 100644 --- a/src/components/common/person/PersonInfo.tsx +++ b/src/components/common/person/PersonInfo.tsx @@ -56,7 +56,7 @@ function PersonInfo({ person }: Props) { - {t('person:info.createdAt')}: {formatDateString(person.createdAt, i18n?.language)} + {t('person:info.createdAt')}: {formatDateString(person.createdAt)} {t('person:info.company')}: {person.company.companyName}