Skip to content

Commit

Permalink
feat: formatRelativeTime add seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Oct 19, 2024
1 parent 3413c73 commit 57c7a60
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,19 @@ export function formatRelativeTime(timestamp: number): string {
const diff = now - timestamp;
const hours = Math.floor(diff / (1000 * 60 * 60));
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((diff % (1000 * 60)) / 1000);

if (hours > 24) {
const days = Math.floor(hours / 24);
return `${days}d`;
} else if (hours > 0) {
return `${hours}h`;
} else if (minutes >= 0) {
} else if (minutes > 0) {
return `${minutes}m`;
} else {
return "just now";
} else if (seconds >= 0) {
return `${seconds}s`;
}
return "0s";
}

export function formatTime(timestamp: number): string {
Expand Down

0 comments on commit 57c7a60

Please sign in to comment.