Added online status

This commit is contained in:
2025-08-31 12:41:21 +02:00
parent 7084159b54
commit 6c1013f0c7
5 changed files with 158 additions and 0 deletions

View File

@@ -18,3 +18,26 @@ export function formatNumber(num: number): string {
export function formatDate(timestamp: number): string {
return dateFormatter.format(new Date(timestamp))
}
export function formatRelativeTime(timestamp: number, type: "past" | "future") {
const now = Date.now()
let diffMs = timestamp - now
const past = diffMs < 0
diffMs = Math.abs(diffMs)
const suffixString = type === "past" ? " ago" : ""
const seconds = Math.floor(diffMs / 1000)
const days = Math.floor(seconds / 86400)
const hours = Math.floor((seconds % 86400) / 3600)
const minutes = Math.floor((seconds % 3600) / 60)
const secs = seconds % 60
const parts: string[] = []
if (days) parts.push(days + " days,")
if (hours) parts.push(hours + " hours,")
if (minutes) parts.push(minutes + " minutes and")
if (!parts.length || secs) parts.push(secs + " seconds")
const str = parts.slice(0, 4).join(" ")
return past ? str + suffixString : "in " + str
}