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 ⭐️

Show order date in user's timezone

Dave Earleyc1c973b615ae
diff --git a/frontend/src/components/routes/ticket-widget/OrderSummaryAndTickets/index.tsx b/frontend/src/components/routes/ticket-widget/OrderSummaryAndTickets/index.tsx
index 03378db80..8374248ff 100644
--- a/frontend/src/components/routes/ticket-widget/OrderSummaryAndTickets/index.tsx
+++ b/frontend/src/components/routes/ticket-widget/OrderSummaryAndTickets/index.tsx
@@ -7,7 +7,7 @@ import {LoadingMask} from "../../../common/LoadingMask";
import {Order, Ticket} from "../../../../types.ts";
import {Card} from "../../../common/Card";
import {AttendeeTicket} from "../../../common/AttendeeTicket";
-import {prettyDate} from "../../../../utilites/dates.ts";
+import {dateToBrowserTz} from "../../../../utilites/dates.ts";
import {PoweredByFooter} from "../../../common/PoweredByFooter";
import {Button, Group} from "@mantine/core";
import {IconPrinter} from "@tabler/icons-react";
@@ -70,7 +70,7 @@ export const OrderSummaryAndTickets = () => {
<div className={classes.orderDetail}>
<div className={classes.orderDetailLabel}>{t`Order Date`}</div>
<div className={classes.orderDetailContent}>
- {prettyDate(order?.created_at, event?.timezone)}
+ {dateToBrowserTz(order?.created_at, event?.timezone)}
</div>
</div>
</Card>
diff --git a/frontend/src/utilites/dates.ts b/frontend/src/utilites/dates.ts
index fb6d076fa..26ffbcce4 100644
--- a/frontend/src/utilites/dates.ts
+++ b/frontend/src/utilites/dates.ts
@@ -8,6 +8,7 @@ import relativeTime from "dayjs/plugin/relativeTime";
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
import advanced from 'dayjs/plugin/advancedFormat';
+import {isSsr} from "./helpers.ts";
dayjs.extend(utc);
dayjs.extend(relativeTime);
@@ -42,3 +43,17 @@ export const utcToTz = (date: undefined | string | Date, tz: string): string | u
// eslint-disable-next-line lingui/no-unlocalized-strings
return dayjs.utc(date).tz(tz).format('YYYY-MM-DDTHH:mm');
};
+
+/**
+ * Converts a datetime to the user's browser timezone, with a fallback timezone for SSR.
+ *
+ * @param date string
+ * @param fallbackTz string
+ */
+export const dateToBrowserTz = (date: string, fallbackTz: string): string => {
+ const userTimezone = !isSsr()
+ ? Intl.DateTimeFormat().resolvedOptions().timeZone
+ : fallbackTz;
+
+ return dayjs.utc(date).tz(userTimezone).format('MMM D, YYYY h:mma z');
+};