This commit is contained in:
parent
1f3609fbad
commit
c185e4423a
2 changed files with 22 additions and 3 deletions
|
|
@ -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 = {
|
export const WithOccurrences: Story = {
|
||||||
args: {
|
args: {
|
||||||
...Default.args,
|
...Default.args,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
/**
|
/**
|
||||||
* Return a readable date time
|
* Return a readable date time
|
||||||
* e.G. Samstag 13-01-2024, 12:00 Uhr
|
* 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) => {
|
export const readableDateTime = (date: string, endDate?: string | null) => {
|
||||||
const dateObj = new Date(date);
|
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 time = dateObj.toLocaleTimeString("de-DE", { timeStyle: "short", timeZone: "Europe/Berlin" });
|
||||||
const base = `${dayName} ${normalDate}, ${time} Uhr`;
|
const base = `${dayName} ${normalDate}, ${time} Uhr`;
|
||||||
if (!endDate) return base;
|
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`;
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue