Skip to content

Commit

Permalink
Show 'now' for post time if it's less than 1s
Browse files Browse the repository at this point in the history
  • Loading branch information
pdelfan committed Mar 12, 2024
1 parent 49a6186 commit 44be5ba
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export function getRelativeTime(dates: string) {
const date = new Date(dates);
const seconds = Math.floor((Date.now() - date.getTime()) / 1000);
const interval = intervals.find((i) => i.seconds < seconds);
if (!interval) return;
if (!interval) return "now";
const count = Math.floor(seconds / interval.seconds);
if (count < 1) return "now";
return `${count}${interval.label}`;
}

Expand Down

0 comments on commit 44be5ba

Please sign in to comment.