Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix formatDateTooltip

Steven Tey145fd54accd4
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/client.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/client.tsx
index 932188c492..1c4caaf913 100644
--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/client.tsx
+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/client.tsx
@@ -264,6 +264,7 @@ export default function PayoutsPageClient() {
interval,
start,
end,
+ timezone: "UTC",
})}
</p>
<div className="grid grid-cols-2 gap-x-6 gap-y-2 px-4 py-3 text-sm">
diff --git a/apps/web/lib/analytics/format-date-tooltip.ts b/apps/web/lib/analytics/format-date-tooltip.ts
index 3f603baae3..8873122df9 100644
--- a/apps/web/lib/analytics/format-date-tooltip.ts
+++ b/apps/web/lib/analytics/format-date-tooltip.ts
@@ -7,13 +7,20 @@ export const formatDateTooltip = (
start,
end,
dataAvailableFrom,
+ timezone = Intl.DateTimeFormat().resolvedOptions().timeZone,
}: {
interval?: string;
start?: string | Date | null;
end?: string | Date | null;
dataAvailableFrom?: Date;
+ timezone?: string;
},
) => {
+ // Convert date to local timezone (or provided timezone if specified)
+ const targetDate = new Date(
+ date.toLocaleString("en-US", { timeZone: timezone }),
+ );
+
if (interval === "all" && dataAvailableFrom) {
start = dataAvailableFrom;
end = new Date(Date.now());
@@ -26,26 +33,26 @@ export const formatDateTooltip = (
);
if (daysDifference <= 2)
- return date.toLocaleTimeString("en-US", {
+ return targetDate.toLocaleTimeString("en-US", {
hour: "numeric",
minute: "numeric",
});
else if (daysDifference > 180)
- return date.toLocaleDateString("en-US", {
+ return targetDate.toLocaleDateString("en-US", {
month: "short",
year: "numeric",
});
} else if (interval) {
switch (interval) {
case "24h":
- return date.toLocaleTimeString("en-US", {
+ return targetDate.toLocaleTimeString("en-US", {
hour: "numeric",
minute: "numeric",
});
case "ytd":
case "1y":
case "all":
- return date.toLocaleDateString("en-US", {
+ return targetDate.toLocaleDateString("en-US", {
month: "short",
year: "numeric",
});
@@ -54,7 +61,7 @@ export const formatDateTooltip = (
}
}
- return date.toLocaleDateString("en-US", {
+ return targetDate.toLocaleDateString("en-US", {
weekday: "short",
month: "short",
day: "numeric",