From 501f8c62738e08314a812b322b4361cda020dac3 Mon Sep 17 00:00:00 2001 From: ivamach Date: Mon, 29 Apr 2024 19:54:07 +0200 Subject: [PATCH] SMA-108: fixed the date --- .../src/components/RateGameComponent.tsx | 42 ++++++++----------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/frontend/sportsmatch-app/src/components/RateGameComponent.tsx b/frontend/sportsmatch-app/src/components/RateGameComponent.tsx index 6943cdd..12aac28 100644 --- a/frontend/sportsmatch-app/src/components/RateGameComponent.tsx +++ b/frontend/sportsmatch-app/src/components/RateGameComponent.tsx @@ -34,7 +34,7 @@ export default function RateGameComponent(p: Props) { console.error(error as ApiError) } } - init() + init() }) useEffect(() => { @@ -53,21 +53,6 @@ export default function RateGameComponent(p: Props) { init() }, []) - const dayOfTheWeek = (year: number, month: number, day: number) => { - const daysOfTheWeek = [ - 'Sunday', - 'Monday', - 'Tuesday', - 'Wednesday', - 'Thursday', - 'Friday', - 'Saturday', - ] - const date = new Date(year, month - 1, day) - const dateIndex = date.getDay() - return daysOfTheWeek[dateIndex] - } - const userProfilePicture = 'pictures/unknown-user-placeholder.png' const opponentProfilePicture = 'pictures/unknown-user-placeholder.png' @@ -106,6 +91,18 @@ export default function RateGameComponent(p: Props) { const value = parseInt(e.target.value) || 0 setOpponentScore(value) } + + const getDateAndTime = (type: string, date: string) => { + const dateStart: string[] = date.split(' ') + if (type === 'date') { + return dateStart[0] + } else if (type === 'time') { + return dateStart[1] + } else { + return null + } + } + return ( <>
@@ -117,14 +114,11 @@ export default function RateGameComponent(p: Props) { {myEvent ? ( <> - {dayOfTheWeek( - parseInt(myEvent.dateStart[0]), - parseInt(myEvent.dateStart[1]), - parseInt(myEvent.dateStart[2]), - )} - , {myEvent.dateStart[3]}:{myEvent.dateStart[4]} - {' - '} - {myEvent.dateEnd[3]}:{myEvent.dateEnd[4]} + {'on ' + getDateAndTime('date', myEvent.dateStart) + + ' at ' + + getDateAndTime('time', myEvent.dateStart) + + ' - ' + + getDateAndTime('time', myEvent.dateEnd)}
{myEvent.placeDTO?.name}{' '}