The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
improve timeAgo to account for future timestamps
Steven Tey7486deb844bf
diff --git a/apps/web/scripts/bulk-create-links.ts b/apps/web/scripts/bulk-create-links.tsindex 65a3566103..d3d246ccd5 100644--- a/apps/web/scripts/bulk-create-links.ts+++ b/apps/web/scripts/bulk-create-links.ts@@ -11,7 +11,7 @@ async function main() {header: true,skipEmptyLines: true,step: (result: { data: any }) => {- const urlObj = new URL(result.data["Short Link"]);+ const urlObj = new URL(result.data["Short link"]);links.push({domain: urlObj.hostname,key: urlObj.pathname.slice(1),diff --git a/packages/utils/src/functions/time-ago.ts b/packages/utils/src/functions/time-ago.tsindex 69147da6fa..3cb3cf5910 100644--- a/packages/utils/src/functions/time-ago.ts+++ b/packages/utils/src/functions/time-ago.ts@@ -10,19 +10,23 @@ export const timeAgo = (): string => {if (!timestamp) return "Never";const diff = Date.now() - new Date(timestamp).getTime();- if (diff < 1000) {- // less than 1 second- return "Just now";- } else if (diff > 82800000) {- // more than 23 hours – similar to how Twitter displays timestamps+ if (diff < 0 || diff > 82800000) {+ // future timestamps or more than 23 hours+ // similar to how Twitter displays timestampsreturn new Date(timestamp).toLocaleDateString("en-US", {month: "short",day: "numeric",year:+ // show year if it's a future timestamp or if it's a different year than current+ diff < 0 ||new Date(timestamp).getFullYear() !== new Date().getFullYear()? "numeric": undefined,});+ } else if (diff < 1000) {+ // less than 1 second+ return "Just now";}+return `${ms(diff)}${withAgo ? " ago" : ""}`;};