Update displayDate to use local time format preferences (#4826)

* update date display time to use local browser locale

* incorporate displaySecond and displayDate

* rewrite

* a

---------

Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
This commit is contained in:
michael
2024-12-16 04:18:52 -06:00
committed by GitHub
parent 94240f9e15
commit 3c48dffdf2
2 changed files with 18 additions and 8 deletions
+13 -3
View File
@@ -72,14 +72,24 @@ export function displayDate(
displayDate = true
): string {
const date = new Date(dateString ?? '')
if (date.toString() === 'Invalid Date') {
if (Number.isNaN(date.valueOf())) {
return ''
} else {
return `${date.toLocaleTimeString([], {
const timeChoices: Intl.DateTimeFormatOptions = {
hour: '2-digit',
minute: '2-digit',
second: displaySecond ? '2-digit' : undefined
})}${displayDate ? ` ${date.getDate()}/${date.getMonth() + 1}` : ''}`
}
const dateChoices: Intl.DateTimeFormatOptions = displayDate
? {
day: 'numeric',
month: 'numeric'
}
: {}
return date.toLocaleString(undefined, {
...timeChoices,
...dateChoices
})
}
}
@@ -301,11 +301,11 @@
<div class="w-full flex justify-between items-baseline">
<div
class="flex flex-wrap text-[0.7em] text-tertiary gap-1 items-center justify-end truncate pr-2"
><div class="truncate">edited by {edited_by}</div><div class="truncate"
>the {displayDate(edited_at)}</div
></div
></div
>
>
<div class="truncate">edited by {edited_by}</div>
<div class="truncate">at {displayDate(edited_at)}</div>
</div>
</div>
</div>
{/each}
</div>