Skip to content

Commit 6584874

Browse files
committed
format dates correctly
1 parent 6367b41 commit 6584874

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

frontend/src/components/Event/EventsCarousel.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,17 @@ const formatEventDate = (startTime: string, endTime: string): string => {
6262
const startDate = new Date(startTime);
6363
const endDate = new Date(endTime);
6464

65-
const sameDay = startDate.toDateString() === endDate.toDateString();
65+
const options: Intl.DateTimeFormatOptions = { day: '2-digit', month: '2-digit', year: 'numeric' };
66+
67+
const formatDate = (date: Date): string => {
68+
return new Intl.DateTimeFormat('en-AU', options).format(date).replace(/\//g, '/');
69+
};
6670

71+
const sameDay = startDate.toDateString() === endDate.toDateString();
72+
6773
if (sameDay) {
68-
return startDate.toLocaleDateString();
74+
return formatDate(startDate); // Return single date in dd/mm/yyyy
6975
} else {
70-
return `${startDate.toLocaleDateString()} - ${endDate.toLocaleDateString()}`;
76+
return `${formatDate(startDate)} - ${formatDate(endDate)}`; // Return date range
7177
}
72-
};
78+
};

0 commit comments

Comments
 (0)