From e7c25b2194406ba8dc05f2ada5f8293aca547f3c Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Sat, 13 Aug 2022 16:25:01 +0100 Subject: [PATCH] Fix flatpickr offsetting date by one hour on initial selection of time-only fields --- packages/bbui/src/Form/Core/DatePicker.svelte | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/bbui/src/Form/Core/DatePicker.svelte b/packages/bbui/src/Form/Core/DatePicker.svelte index 39a7d9d626..c3eee7505f 100644 --- a/packages/bbui/src/Form/Core/DatePicker.svelte +++ b/packages/bbui/src/Form/Core/DatePicker.svelte @@ -59,6 +59,13 @@ // If time only set date component to 2000-01-01 if (timeOnly) { + // Classic flackpickr causing issues. + // When selecting a time first the first time for a "time only" field, + // the time is always offset by 1 hour for some reason (regardless of time + // zone) so we need to correct it. + if (!value && newValue) { + newValue = new Date(dates[0].getTime() + 60 * 60 * 1000).toISOString() + } newValue = `2000-01-01T${newValue.split("T")[1]}` }