From b2b88d1947df397376b3be4c517318bb418e6b3f Mon Sep 17 00:00:00 2001 From: Timofey Date: Fri, 23 May 2025 15:22:22 +0300 Subject: [PATCH] date formatter fix --- .../(urls)/search/components/SearchCard.tsx | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/frontend/app/(urls)/search/components/SearchCard.tsx b/frontend/app/(urls)/search/components/SearchCard.tsx index 526da6c..dc3e547 100644 --- a/frontend/app/(urls)/search/components/SearchCard.tsx +++ b/frontend/app/(urls)/search/components/SearchCard.tsx @@ -4,6 +4,25 @@ import Button from '@/components/ui/Button' import { SearchCardProps } from '@/app/types' import noPhoto from '../../../../public/images/noPhoto.png' +const formatDateTime = (dateTimeString: string): string => { + const date = new Date(dateTimeString) + const formatter = new Intl.DateTimeFormat('ru-RU', { + day: 'numeric', + month: 'long', + year: 'numeric', + }) + + const timeFormatter = new Intl.DateTimeFormat('ru-RU', { + hour: '2-digit', + minute: '2-digit', + }) + + const dateStr = formatter.format(date).replace(' г.', '') + const timeStr = timeFormatter.format(date) + + return `${dateStr}, ${timeStr}` +} + const SearchCard = ({ id, username, @@ -104,7 +123,9 @@ const SearchCard = ({ {userRequest === 'Могу перевезти' && (
Отправление:{' '} - {formatted_departure} + + {formatDateTime(formatted_departure)} +
)} @@ -136,7 +157,7 @@ const SearchCard = ({ {userRequest === 'Нужен перевозчик' && (
Дата доставки:{' '} - {formatted_arrival} + {formatDateTime(formatted_arrival)}
)} @@ -166,7 +187,9 @@ const SearchCard = ({ {userRequest === 'Могу перевезти' && (
Прибытие:{' '} - {formatted_arrival} + + {formatDateTime(formatted_arrival)} +
)} @@ -275,7 +298,7 @@ const SearchCard = ({ {userRequest === 'Могу перевезти' && (
Прибытие:{' '} - {formatted_arrival} + {formatDateTime(formatted_arrival)}
)}