This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
atsebay.t/ui/src/components/DateTimeInput.svelte
Pierre-Olivier Mercier 9351b39a4b
All checks were successful
continuous-integration/drone/push Build is passing
Handle invalid date
2022-09-16 13:44:18 +02:00

27 lines
517 B
Svelte

<script>
import dayjs from 'dayjs';
export let format = 'YYYY-MM-DD HH:mm';
export let date = new Date();
let className = '';
export { className as class };
export let id = null;
let internal;
const input = (x) => (internal = dayjs(x).format(format));
const output = (x) => {
const d = dayjs(x, format).toDate();
if (d) {
date = d.toISOString();
}
};
$: input(date)
$: output(internal)
</script>
<input type="datetime-local" class={className} id={id} bind:value={internal}>