From cdc94dce5f4b2f504d1ee19aedf72df1490433a4 Mon Sep 17 00:00:00 2001 From: alex <48489896+devnaumov@users.noreply.github.com> Date: Wed, 28 Jan 2026 12:30:09 +0100 Subject: [PATCH] dbeaver/pro#8089 validate date before formatting (#4091) * dbeaver/pro#8089 validate date before formatting * dbeaver/pro#8089 treat date and time the same --------- Co-authored-by: Daria Marutkina <125263541+dariamarutkina@users.noreply.github.com> --- .../CellFormatters/DateTimeFormatter.tsx | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/Formatters/CellFormatters/DateTimeFormatter.tsx b/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/Formatters/CellFormatters/DateTimeFormatter.tsx index 764a322c52..d33538ecee 100644 --- a/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/Formatters/CellFormatters/DateTimeFormatter.tsx +++ b/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/Formatters/CellFormatters/DateTimeFormatter.tsx @@ -16,6 +16,10 @@ import { DateTimeKind, useFormattingContext } from '../../FormattingContext.js'; import { TableDataContext } from '../../TableDataContext.js'; import type { ICellFormatterProps } from '../ICellFormatterProps.js'; +function isValidDate(date: Date): boolean { + return !isNaN(date.getTime()); +} + export const DateTimeFormatter = observer(function DateTimeFormatter() { const tableDataContext = useContext(TableDataContext); const formattingContext = useFormattingContext(); @@ -34,12 +38,13 @@ export const DateTimeFormatter = observer(function DateTime return ; } - let value = displayValue; + let date = new Date(displayValue); + let dateFormatter: Intl.DateTimeFormat | null = null; if (formattingContext.formatters) { const extendedDateKind = formattingContext.getExtendedDateKind(cellContext.cell.column); - let dateFormatter: Intl.DateTimeFormat | null = null; + switch (extendedDateKind) { case DateTimeKind.DateTime: dateFormatter = formattingContext.formatters.dateTime; @@ -51,19 +56,22 @@ export const DateTimeFormatter = observer(function DateTime dateFormatter = formattingContext.formatters.dateOnly; break; } - if (dateFormatter) { - if (DateTimeKind.TimeOnly === extendedDateKind) { - const [h = 0, m = 0, s = 0] = displayValue.split(':').map(Number); - const date = new Date(); - date.setHours(h, m, s, 0); - value = dateFormatter.format(date); - } else { - const date = new Date(displayValue); - value = dateFormatter.format(date); - } + + if (DateTimeKind.TimeOnly === extendedDateKind) { + const [h = 0, m = 0, s = 0] = displayValue.split(':').map(Number); + const time = new Date(); + time.setHours(h, m, s, 0); + + date = time; } } + let value = displayValue; + + if (dateFormatter && isValidDate(date)) { + value = dateFormatter.format(date); + } + return (
{value}