Skip to content

Commit

Permalink
Update displayDate to use local time format preferences (#4826)
Browse files Browse the repository at this point in the history
* update date display time to use local browser locale

* incorporate displaySecond and displayDate

* rewrite

* a

---------

Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
  • Loading branch information
mzhang28 and rubenfiszel authored Dec 16, 2024
1 parent e4bffe4 commit d391930
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 13 additions & 3 deletions frontend/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
}

Expand Down
10 changes: 5 additions & 5 deletions frontend/src/routes/(root)/(logged)/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit d391930

Please sign in to comment.