diff --git a/packages/bbui/package.json b/packages/bbui/package.json index f313dd04c0..de1fc0db5e 100644 --- a/packages/bbui/package.json +++ b/packages/bbui/package.json @@ -84,7 +84,7 @@ "@spectrum-css/vars": "3.0.1", "dayjs": "^1.10.4", "easymde": "^2.16.1", - "svelte-flatpickr": "^3.3.2", + "svelte-flatpickr": "3.2.3", "svelte-portal": "^1.0.0" }, "resolutions": { diff --git a/packages/frontend-core/src/components/grid/cells/DateCell.svelte b/packages/frontend-core/src/components/grid/cells/DateCell.svelte index f5b1acb1c8..53b159ee30 100644 --- a/packages/frontend-core/src/components/grid/cells/DateCell.svelte +++ b/packages/frontend-core/src/components/grid/cells/DateCell.svelte @@ -13,10 +13,10 @@ let flatpickr let isOpen - // adding the 0- will turn a string like 00:00:00 into a valid ISO + // 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}`) - $: timeOnly = !isNaN(time) || schema?.timeOnly + $: isTimeValue = !isNaN(new Date(`0-${value}`)) + $: timeOnly = isTimeValue || schema?.timeOnly $: dateOnly = schema?.dateOnly $: format = timeOnly ? "HH:mm:ss" @@ -24,6 +24,19 @@ ? "MMM D YYYY" : "MMM D YYYY, HH:mm" $: editable = focused && !readonly + $: displayValue = getDisplayValue(value, format, timeOnly, isTimeValue) + + const getDisplayValue = (value, format, timeOnly, isTimeValue) => { + if (!value) { + return "" + } + // Parse full date strings + if (!timeOnly || !isTimeValue) { + return dayjs(value).format(format) + } + // Otherwise must be a time string + return dayjs(`0-${value}`).format(format) + } // Ensure we close flatpickr when unselected $: { @@ -49,7 +62,7 @@