From ced37a2daf6a7894f191e93375e036ca9ce5f210 Mon Sep 17 00:00:00 2001 From: ybaskaran <34709414+ybaskaran@users.noreply.github.com> Date: Tue, 11 Jun 2024 08:28:52 +0200 Subject: [PATCH] fix(TMC-27619/cellDate): enable tz conversion with sourceTz (#5332) * fix(TMC-27619/cellDate): enable tz offset conversion with sourceTz * fix(TMC-27619/cellDate): enable tz offset conversion with sourceTz --- .changeset/five-ears-guess.md | 5 +++++ .../VirtualizedList/CellDatetime/CellDatetime.component.js | 1 + .../src/VirtualizedList/CellDatetime/CellDatetime.test.js | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/five-ears-guess.md diff --git a/.changeset/five-ears-guess.md b/.changeset/five-ears-guess.md new file mode 100644 index 00000000000..7361bf42be7 --- /dev/null +++ b/.changeset/five-ears-guess.md @@ -0,0 +1,5 @@ +--- +"@talend/react-components": patch +--- + +fix(TMC-27619/cellDate): enable tz offset conversion with sourceTz diff --git a/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.component.js b/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.component.js index 5c1e44353ba..3c171893519 100644 --- a/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.component.js +++ b/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.component.js @@ -35,6 +35,7 @@ export function computeValue(cellData, columnData, t) { } else if (columnData.mode === 'format') { if (columnData.timeZone) { return dateUtils.formatToTimeZone(dateFNS, columnData.pattern || DATE_TIME_FORMAT, { + ...(columnData.sourceTimeZone && { sourceTimeZone: columnData.sourceTimeZone }), timeZone: columnData.timeZone, locale: getLocale(t), }); diff --git a/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.test.js b/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.test.js index eac23203e22..5459b71e0cc 100644 --- a/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.test.js +++ b/packages/components/src/VirtualizedList/CellDatetime/CellDatetime.test.js @@ -167,18 +167,22 @@ describe('CellDatetime', () => { mode: 'format', pattern: 'YYYY-MM-DD HH:mm:ss', timeZone: 'Pacific/Niue', + sourceTimeZone: 'Europe/Paris', }; const t = jest.fn(); const cellData = 1474495200000; - computeValue(cellData, columnData, t); + const expectedStrDate = '2016-09-22 09:00:00'; + const computedStrOffset = computeValue(cellData, columnData, t); // then + expect(computedStrOffset).toEqual(expectedStrDate); expect(dateUtils.formatToTimeZone).toHaveBeenCalledWith( new Date(cellData), columnData.pattern, { timeZone: columnData.timeZone, + sourceTimeZone: columnData.sourceTimeZone, locale: getLocale(t), }, );