forked from BRETT/BRETT
Initial Commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { useNow } from '@vueuse/core'
|
||||
|
||||
// Auto-aktualisierende relative Zeit („vor 3 Min") — tickt alle 30s,
|
||||
// damit offene Seiten ohne Reload aktuell bleiben
|
||||
export function useTimeAgo() {
|
||||
const now = useNow({ interval: 30_000 })
|
||||
|
||||
return (value: string) => {
|
||||
const seconds = Math.max(0, Math.floor((now.value.getTime() - new Date(value).getTime()) / 1000))
|
||||
if (seconds < 60) return 'gerade eben'
|
||||
const minutes = Math.floor(seconds / 60)
|
||||
if (minutes < 60) return `vor ${minutes} Min`
|
||||
const hours = Math.floor(minutes / 60)
|
||||
if (hours < 24) return `vor ${hours} Std`
|
||||
const days = Math.floor(hours / 24)
|
||||
if (days < 30) return `vor ${days} T`
|
||||
const months = Math.floor(days / 30)
|
||||
if (months < 12) return `vor ${months} Mon`
|
||||
return `vor ${Math.floor(months / 12)} J`
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user