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.

improve getDaysDifference

Steven Teycf43af6d17c2
diff --git a/apps/web/lib/analytics/format-date-tooltip.ts b/apps/web/lib/analytics/format-date-tooltip.ts
index 8873122df9..e36f1a2423 100644
--- a/apps/web/lib/analytics/format-date-tooltip.ts
+++ b/apps/web/lib/analytics/format-date-tooltip.ts
@@ -27,10 +27,7 @@ export const formatDateTooltip = (
}
if (start && end) {
- const daysDifference = getDaysDifference(
- typeof start === "string" ? new Date(start) : start,
- typeof end === "string" ? new Date(end) : end,
- );
+ const daysDifference = getDaysDifference(start, end);
if (daysDifference <= 2)
return targetDate.toLocaleTimeString("en-US", {
diff --git a/packages/utils/src/functions/datetime/get-days-difference.ts b/packages/utils/src/functions/datetime/get-days-difference.ts
index ada55936aa..639a63b075 100644
--- a/packages/utils/src/functions/datetime/get-days-difference.ts
+++ b/packages/utils/src/functions/datetime/get-days-difference.ts
@@ -3,8 +3,8 @@ export const getDaysDifference = (
startDate: Date | string,
endDate: Date | string,
) => {
- startDate = new Date(startDate);
- endDate = new Date(endDate);
+ startDate = typeof startDate === "string" ? new Date(startDate) : startDate;
+ endDate = typeof endDate === "string" ? new Date(endDate) : endDate;
const diffTime = Math.abs(endDate.getTime() - startDate.getTime());
return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
};