1
0
Fork 0
mirror of synced 2024-06-29 11:31:06 +12:00
budibase/packages/bbui/src/Table/DateTimeRenderer.svelte

30 lines
606 B
Svelte

<script>
import dayjs from "dayjs"
export let value
export let schema
// adding the 0- will turn a string like 00:00:00 into a valid ISO
// date, but will make actual ISO dates invalid
$: time = new Date(`0-${value}`)
$: isTimeOnly = !isNaN(time) || schema?.timeOnly
$: isDateOnly = schema?.dateOnly
$: format = isTimeOnly
? "HH:mm:ss"
: isDateOnly
? "MMMM D YYYY"
: "MMMM D YYYY, HH:mm"
</script>
<div>
{dayjs(isTimeOnly ? time : value).format(format)}
</div>
<style>
div {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>