Skip to content

Commit

Permalink
fix(TMC-27619/cellDate): enable tz conversion with sourceTz (#5332)
Browse files Browse the repository at this point in the history
* fix(TMC-27619/cellDate): enable tz offset conversion with sourceTz

* fix(TMC-27619/cellDate): enable tz offset conversion with sourceTz
  • Loading branch information
ybaskaran authored Jun 11, 2024
1 parent 3bd16fc commit ced37a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/five-ears-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@talend/react-components": patch
---

fix(TMC-27619/cellDate): enable tz offset conversion with sourceTz
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
);
Expand Down

0 comments on commit ced37a2

Please sign in to comment.