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 27b106af5b..764a322c52 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 @@ -42,16 +42,25 @@ export const DateTimeFormatter = observer(function DateTime let dateFormatter: Intl.DateTimeFormat | null = null; switch (extendedDateKind) { case DateTimeKind.DateTime: - case DateTimeKind.TimeOnly: dateFormatter = formattingContext.formatters.dateTime; break; + case DateTimeKind.TimeOnly: + dateFormatter = formattingContext.formatters.timeOnly; + break; case DateTimeKind.DateOnly: dateFormatter = formattingContext.formatters.dateOnly; break; } if (dateFormatter) { - 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 date = new Date(); + date.setHours(h, m, s, 0); + value = dateFormatter.format(date); + } else { + const date = new Date(displayValue); + value = dateFormatter.format(date); + } } } diff --git a/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/FormattingContext.ts b/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/FormattingContext.ts index cc77772588..0b7b2f1101 100644 --- a/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/FormattingContext.ts +++ b/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/FormattingContext.ts @@ -19,6 +19,7 @@ export interface IDataGridFormatters { locale: string; dateTime: Intl.DateTimeFormat; dateOnly: Intl.DateTimeFormat; + timeOnly: Intl.DateTimeFormat; number: Intl.NumberFormat; } diff --git a/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/helpers/detectDateTimeKind.test.ts b/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/helpers/detectDateTimeKind.test.ts index 958a095dd3..a3d0d3b453 100644 --- a/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/helpers/detectDateTimeKind.test.ts +++ b/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/helpers/detectDateTimeKind.test.ts @@ -1,6 +1,6 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2025 DBeaver Corp and others + * Copyright (C) 2020-2026 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. @@ -17,10 +17,10 @@ describe('detectDateTimeKind', () => { expect(detectDateTimeKind('1999-12-31')).toBe(DateTimeKind.DateOnly); }); - test('should detect time-only format (HH:MM:SS)', () => { + test('should detect time-only format (HH:MM:SS or HH:MM)', () => { expect(detectDateTimeKind('14:30:00')).toBe(DateTimeKind.TimeOnly); expect(detectDateTimeKind('00:00:00')).toBe(DateTimeKind.TimeOnly); - expect(detectDateTimeKind('23:59:59')).toBe(DateTimeKind.TimeOnly); + expect(detectDateTimeKind('23:59')).toBe(DateTimeKind.TimeOnly); expect(detectDateTimeKind('14:30:00.123')).toBe(DateTimeKind.TimeOnly); }); diff --git a/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/helpers/detectDateTimeKind.ts b/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/helpers/detectDateTimeKind.ts index 09343e4cf6..8b0e4f04e0 100644 --- a/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/helpers/detectDateTimeKind.ts +++ b/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/helpers/detectDateTimeKind.ts @@ -10,13 +10,14 @@ import { DateTimeKind } from '../FormattingContext.js'; const DATE_ONLY_REGEX = /^\d{4}-\d{2}-\d{2}$/; const TIME_ONLY_REGEX = /^\d{2}:\d{2}:\d{2}/; +const TIME_ONLY_NO_SECONDS_REGEX = /^\d{2}:\d{2}$/; export function detectDateTimeKind(displayValue: string): DateTimeKind { if (DATE_ONLY_REGEX.test(displayValue)) { return DateTimeKind.DateOnly; } - if (TIME_ONLY_REGEX.test(displayValue) && !displayValue.includes('-')) { + if ((TIME_ONLY_REGEX.test(displayValue) || TIME_ONLY_NO_SECONDS_REGEX.test(displayValue)) && !displayValue.includes('-')) { return DateTimeKind.TimeOnly; } diff --git a/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/useFormatting.ts b/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/useFormatting.ts index 04b68401ad..8d6fbeb597 100644 --- a/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/useFormatting.ts +++ b/webapp/packages/plugin-data-spreadsheet-new/src/DataGrid/useFormatting.ts @@ -38,6 +38,11 @@ export function useFormatting(tableData: ITableData, cache: ResultSetCacheAction return { locale, + timeOnly: new Intl.DateTimeFormat(locale, { + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + }), dateTime: new Intl.DateTimeFormat(locale, { year: 'numeric', month: 'numeric', @@ -50,7 +55,6 @@ export function useFormatting(tableData: ITableData, cache: ResultSetCacheAction year: 'numeric', month: 'numeric', day: 'numeric', - timeZone: 'UTC', }), number: new Intl.NumberFormat(locale), };