From f2100a2f2bc29433f58255ded464a9e4642b6367 Mon Sep 17 00:00:00 2001 From: evan-scales Date: Tue, 16 Apr 2024 16:25:42 -0400 Subject: [PATCH] 516: Show end date on day overflow --- FU.SPA/src/components/PostCard.jsx | 31 ++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/FU.SPA/src/components/PostCard.jsx b/FU.SPA/src/components/PostCard.jsx index 1bd8bd58..0d562bdb 100644 --- a/FU.SPA/src/components/PostCard.jsx +++ b/FU.SPA/src/components/PostCard.jsx @@ -46,6 +46,7 @@ const PostCard = ({ post, showActions, onTagClick, showJoinedStatus }) => { if (post.startTime) { let startOfToday = dayjs().startOf('day'); let postStartDateTime = dayjs(post.startTime); + let postEndDateTime = dayjs(post.endTime); let startDate = dayjs(post.startTime).format('MMM D, YYYY'); if (postStartDateTime < startOfToday) { @@ -60,6 +61,22 @@ const PostCard = ({ post, showActions, onTagClick, showJoinedStatus }) => { startDate = dayjs(post.startTime).format('MMM D'); } + let endDate = ''; + if (!postEndDateTime.isSame(postStartDateTime, 'day')) { + endDate = dayjs(post.endTime).format('MMM D, YYYY'); + if (postEndDateTime < startOfToday) { + // Use default + } else if (postEndDateTime < startOfToday.add(1, 'day')) { + endDate = 'Today'; + } else if (postEndDateTime < startOfToday.add(2, 'day')) { + endDate = 'Tomorrow'; + } else if (postEndDateTime < startOfToday.add(6, 'day')) { + endDate = dayjs(post.endTime).format('ddd'); + } else if (postEndDateTime < startOfToday.add(1, 'year')) { + endDate = dayjs(post.endTime).format('MMM D'); + } + } + var startTime = new Date(post.startTime).toLocaleString('en-US', { timeStyle: 'short', }); @@ -67,7 +84,11 @@ const PostCard = ({ post, showActions, onTagClick, showJoinedStatus }) => { timeStyle: 'short', }); - dateTimeString = `${startDate}, ${startTime} - ${endTime}`; + dateTimeString = `${startDate}, ${startTime} - `; + if (endDate !== '') { + dateTimeString += `${endDate}, `; + } + dateTimeString += `${endTime}`; } else { dateTimeString = 'No time'; } @@ -127,9 +148,11 @@ const PostCard = ({ post, showActions, onTagClick, showJoinedStatus }) => { {post.game} - - {dateTimeString} - + + + {dateTimeString} + +