Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

Improve date and time display on event page (fixes #54)

Dave Earley4acbd51a195f
diff --git a/frontend/src/components/common/EventDateRange/index.tsx b/frontend/src/components/common/EventDateRange/index.tsx
new file mode 100644
index 000000000..64411fb77
--- /dev/null
+++ b/frontend/src/components/common/EventDateRange/index.tsx
@@ -0,0 +1,32 @@
+import {Event} from "../../../types.ts";
+import {formatDate} from "../../../utilites/dates.ts";
+
+interface EventDateRangeProps {
+ event: Event
+}
+
+export const EventDateRange = ({event}: EventDateRangeProps) => {
+ const startDateFormatted = formatDate(event.start_date, "ddd, MMM D, YYYY h:mm A", event.timezone);
+ const endDateFormatted = event.end_date ? formatDate(event.end_date, "ddd, MMM D, YYYY h:mm A", event.timezone) : null;
+ const sameDayFormatted = formatDate(event.start_date, "dddd, MMMM D", event.timezone);
+ const startTimeFormatted = formatDate(event.start_date, "h:mm A", event.timezone);
+ const endTimeFormatted = event.end_date ? formatDate(event.end_date, "h:mm A", event.timezone) : null;
+ const timezone = formatDate(event.start_date, "z", event.timezone);
+
+ const isSameDay = event.end_date && event.start_date.substring(0, 10) === event.end_date.substring(0, 10);
+
+ return (
+ <>
+ {isSameDay ? (
+ <span>
+ {sameDayFormatted} · {startTimeFormatted} - {endTimeFormatted} {timezone}
+ </span>
+ ) : (
+ <span>
+ {startDateFormatted}
+ {endDateFormatted && ` - ${endDateFormatted}`} {timezone}
+ </span>
+ )}
+ </>
+ );
+}
diff --git a/frontend/src/components/layouts/EventHomepage/EventInformation/index.tsx b/frontend/src/components/layouts/EventHomepage/EventInformation/index.tsx
index 54a862efc..e337d412a 100644
--- a/frontend/src/components/layouts/EventHomepage/EventInformation/index.tsx
+++ b/frontend/src/components/layouts/EventHomepage/EventInformation/index.tsx
@@ -9,6 +9,7 @@ import {ShareComponent} from "../../../common/ShareIcon";
import {eventCoverImageUrl, eventHomepageUrl} from "../../../../utilites/urlHelper.ts";
import {FC} from "react";
import {Event} from "../../../../types.ts";
+import {EventDateRange} from "../../../common/EventDateRange";
export const EventInformation: FC<{
event: Event
@@ -39,15 +40,8 @@ export const EventInformation: FC<{
<h2>{t`Date & Time`}</h2>
<div className={classes.details}>
<IconCalendar size={20}/>
- <div className={classes.detail}>
- <div>
- {prettyDate(event.start_date, event.timezone)}
- </div>
- {event?.end_date && (
- <div>
- {prettyDate(event.end_date, event.timezone)}
- </div>
- )}
+ <div>
+ <EventDateRange event={event}/>
</div>
</div>
</div>
diff --git a/frontend/src/utilites/dates.ts b/frontend/src/utilites/dates.ts
index 96bd06a02..fb6d076fa 100644
--- a/frontend/src/utilites/dates.ts
+++ b/frontend/src/utilites/dates.ts
@@ -7,10 +7,12 @@ import dayjs from "dayjs";
import relativeTime from "dayjs/plugin/relativeTime";
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
+import advanced from 'dayjs/plugin/advancedFormat';
dayjs.extend(utc);
dayjs.extend(relativeTime);
dayjs.extend(timezone);
+dayjs.extend(advanced)
export const prettyDate = (date: string, tz: string): string => {
// eslint-disable-next-line lingui/no-unlocalized-strings