From 13ccc3fe7fe9a3e08ee1d4e48f544b0d66491c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Wed, 30 Nov 2022 18:34:05 +0100 Subject: [PATCH] Date display improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/components/ui/stack/stack.tsx | 2 +- .../components/ui/textarea/textarea.tsx | 2 +- .../features/event/components/event-date.tsx | 5 ++-- .../features/event/event-information.tsx | 29 ++++++++++++++++--- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/app/soapbox/components/ui/stack/stack.tsx b/app/soapbox/components/ui/stack/stack.tsx index 1931904b9..fed361e93 100644 --- a/app/soapbox/components/ui/stack/stack.tsx +++ b/app/soapbox/components/ui/stack/stack.tsx @@ -52,7 +52,7 @@ const Stack = React.forwardRef((props, ref: React.Legacy = ({ status }) => { if (event.end_time) { const endDate = new Date(event.end_time); - const sameDay = startDate.getDate() === endDate.getDate() && startDate.getMonth() === endDate.getMonth() && startDate.getFullYear() === endDate.getFullYear(); + const sameYear = startDate.getFullYear() === endDate.getFullYear(); + const sameDay = startDate.getDate() === endDate.getDate() && startDate.getMonth() === endDate.getMonth() && sameYear; if (sameDay) { date = ( <> - + {' - '} diff --git a/app/soapbox/features/event/event-information.tsx b/app/soapbox/features/event/event-information.tsx index 9068d2d5c..54c5f5f40 100644 --- a/app/soapbox/features/event/event-information.tsx +++ b/app/soapbox/features/event/event-information.tsx @@ -88,7 +88,12 @@ const EventInformation: React.FC = ({ params }) => { const renderEventDate = useCallback(() => { const event = status?.event; - if (!event?.start_time) return null; + const startDate = new Date(event.start_time); + const endDate = new Date(event.end_time); + + if (!startDate) return null; + + const sameDay = endDate && startDate.getDate() === endDate.getDate() && startDate.getMonth() === endDate.getMonth() && startDate.getFullYear() === endDate.getFullYear(); return ( @@ -98,10 +103,26 @@ const EventInformation: React.FC = ({ params }) => { - - {event.end_time && (<> + + {endDate && (<> {' - '} - + )}