diff --git a/src/pageComponents/Event/Event.stories.tsx b/src/pageComponents/Event/Event.stories.tsx index 63a8db4..a0b8ccd 100644 --- a/src/pageComponents/Event/Event.stories.tsx +++ b/src/pageComponents/Event/Event.stories.tsx @@ -77,6 +77,14 @@ export const WithPhoto: Story = { } } +export const WithEndDateOnDifferentDay: Story = { + args: { + ...Default.args, + date: "2024-12-02T13:00:00Z", + endDateTime: "2024-12-04T14:00:00Z", + }, +} + export const WithOccurrences: Story = { args: { ...Default.args, diff --git a/src/utils/readableDate.ts b/src/utils/readableDate.ts index 81dee20..1450ebf 100644 --- a/src/utils/readableDate.ts +++ b/src/utils/readableDate.ts @@ -1,7 +1,8 @@ /** * Return a readable date time * e.G. Samstag 13-01-2024, 12:00 Uhr - * With endDate: Samstag 13-01-2024, 12:00 Uhr bis 14:00 Uhr + * With endDate (same day): Samstag 13-01-2024, 12:00 Uhr bis 14:00 Uhr + * With endDate (other day): Samstag 13-01-2024, 12:00 Uhr bis 15-01-2024, 14:00 Uhr */ export const readableDateTime = (date: string, endDate?: string | null) => { const dateObj = new Date(date); @@ -10,6 +11,16 @@ export const readableDateTime = (date: string, endDate?: string | null) => { const time = dateObj.toLocaleTimeString("de-DE", { timeStyle: "short", timeZone: "Europe/Berlin" }); const base = `${dayName} ${normalDate}, ${time} Uhr`; if (!endDate) return base; - const endTime = new Date(endDate).toLocaleTimeString("de-DE", { timeStyle: "short", timeZone: "Europe/Berlin" }); - return `${base} bis ${endTime} Uhr`; + + const endObj = new Date(endDate); + const endTime = endObj.toLocaleTimeString("de-DE", { timeStyle: "short", timeZone: "Europe/Berlin" }); + + const isSameDay = + dateObj.toLocaleDateString("de-DE", { timeZone: "Europe/Berlin" }) === + endObj.toLocaleDateString("de-DE", { timeZone: "Europe/Berlin" }); + + if (isSameDay) return `${base} bis ${endTime} Uhr`; + + const endNormalDate = endObj.toLocaleDateString("de-DE", { dateStyle: "medium" }); + return `${base} bis ${endNormalDate}, ${endTime} Uhr`; } \ No newline at end of file