fix: make relative dates more compact
This commit is contained in:
1 parent
53227f799e
commit
e54031faae
1 file changed
+5
-4
@@ -1,6 +1,10 @@
|
||||
<script lang="ts">
|
||||
export let date: Date
|
||||
export let relativeTo: Date | undefined = undefined
|
||||
export let options: Intl.RelativeTimeFormatOptions = {
|
||||
numeric: 'auto',
|
||||
style: 'narrow',
|
||||
}
|
||||
|
||||
function formatRelativeDate(date: Date) {
|
||||
const now = relativeTo?.getTime() ?? Date.now()
|
||||
@@ -21,10 +25,7 @@
|
||||
if (diffInMillis >= thresholds[i].threshold) {
|
||||
const value = Math.round(diffInMillis / thresholds[i].threshold)
|
||||
|
||||
const rtf = new Intl.RelativeTimeFormat('en', {
|
||||
numeric: 'always',
|
||||
style: 'long',
|
||||
})
|
||||
const rtf = new Intl.RelativeTimeFormat('en', options)
|
||||
|
||||
return rtf.format(-value, thresholds[i].unit as any)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user