diff --git a/.changeset/five-ears-guess.md b/.changeset/five-ears-guess.md new file mode 100644 index 0000000000..7361bf42be --- /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 5c1e44353b..3c17189351 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 eac23203e2..5459b71e0c 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), }, );