Skip to content

Commit 145fd54

Browse files
committed
fix formatDateTooltip
1 parent 3b87896 commit 145fd54

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

apps/web/app/(ee)/admin.dub.co/(dashboard)/payouts/client.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ export default function PayoutsPageClient() {
264264
interval,
265265
start,
266266
end,
267+
timezone: "UTC",
267268
})}
268269
</p>
269270
<div className="grid grid-cols-2 gap-x-6 gap-y-2 px-4 py-3 text-sm">

apps/web/lib/analytics/format-date-tooltip.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@ export const formatDateTooltip = (
77
start,
88
end,
99
dataAvailableFrom,
10+
timezone = Intl.DateTimeFormat().resolvedOptions().timeZone,
1011
}: {
1112
interval?: string;
1213
start?: string | Date | null;
1314
end?: string | Date | null;
1415
dataAvailableFrom?: Date;
16+
timezone?: string;
1517
},
1618
) => {
19+
// Convert date to local timezone (or provided timezone if specified)
20+
const targetDate = new Date(
21+
date.toLocaleString("en-US", { timeZone: timezone }),
22+
);
23+
1724
if (interval === "all" && dataAvailableFrom) {
1825
start = dataAvailableFrom;
1926
end = new Date(Date.now());
@@ -26,26 +33,26 @@ export const formatDateTooltip = (
2633
);
2734

2835
if (daysDifference <= 2)
29-
return date.toLocaleTimeString("en-US", {
36+
return targetDate.toLocaleTimeString("en-US", {
3037
hour: "numeric",
3138
minute: "numeric",
3239
});
3340
else if (daysDifference > 180)
34-
return date.toLocaleDateString("en-US", {
41+
return targetDate.toLocaleDateString("en-US", {
3542
month: "short",
3643
year: "numeric",
3744
});
3845
} else if (interval) {
3946
switch (interval) {
4047
case "24h":
41-
return date.toLocaleTimeString("en-US", {
48+
return targetDate.toLocaleTimeString("en-US", {
4249
hour: "numeric",
4350
minute: "numeric",
4451
});
4552
case "ytd":
4653
case "1y":
4754
case "all":
48-
return date.toLocaleDateString("en-US", {
55+
return targetDate.toLocaleDateString("en-US", {
4956
month: "short",
5057
year: "numeric",
5158
});
@@ -54,7 +61,7 @@ export const formatDateTooltip = (
5461
}
5562
}
5663

57-
return date.toLocaleDateString("en-US", {
64+
return targetDate.toLocaleDateString("en-US", {
5865
weekday: "short",
5966
month: "short",
6067
day: "numeric",

0 commit comments

Comments
 (0)