From f91935b92590330c530daaf69cdafe84756f0a9d Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Sat, 6 May 2023 19:46:28 +0530 Subject: [PATCH] test: extDB offset corrections --- tests/playwright/tests/db/timezone.spec.ts | 71 +++++++++++++--------- 1 file changed, 41 insertions(+), 30 deletions(-) diff --git a/tests/playwright/tests/db/timezone.spec.ts b/tests/playwright/tests/db/timezone.spec.ts index db1c8456a4..d127408c1d 100644 --- a/tests/playwright/tests/db/timezone.spec.ts +++ b/tests/playwright/tests/db/timezone.spec.ts @@ -447,7 +447,10 @@ test.describe('External DB - DateTime column', async () => { const expectedDisplayValues = { pg: { DatetimeWithoutTz: ['2023-04-27 10:00', '2023-04-27 10:00'], - DatetimeWithTz: ['2023-04-27 10:00', getDateTimeInLocalTimeZone('2023-04-27 04:30:00+00:00')], + DatetimeWithTz: [ + getDateTimeInLocalTimeZone('2023-04-27 10:00:00+00:00'), + getDateTimeInLocalTimeZone('2023-04-27 04:30:00+00:00'), + ], }, sqlite: { // without +HH:MM information, display value is same as inserted value @@ -525,6 +528,10 @@ test.describe('External DB - DateTime column', async () => { test('Verify display value, UI insert, API response', async () => { // get timezone offset const timezoneOffset = new Date().getTimezoneOffset(); + const hours = Math.floor(Math.abs(timezoneOffset) / 60); + const minutes = Math.abs(timezoneOffset % 60); + const sign = timezoneOffset <= 0 ? '+' : '-'; + const formattedOffset = `${sign}${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`; await dashboard.treeView.openBase({ title: 'datetimetable' }); await dashboard.treeView.openTable({ title: 'MyTable' }); @@ -587,38 +594,42 @@ test.describe('External DB - DateTime column', async () => { let dateTimeWithoutTz = records.list.map(record => record.DatetimeWithoutTz); let dateTimeWithTz = records.list.map(record => record.DatetimeWithTz); - const expectedDateTimeWithoutTz = [ - 'Thu, 27 Apr 2023 10:00:00 GMT', - 'Thu, 27 Apr 2023 10:00:00 GMT', - 'Thu, 27 Apr 2023 10:00:00 GMT', - ]; - const expectedDateTimeWithTz = [ - 'Thu, 27 Apr 2023 10:00:00 GMT', - 'Thu, 27 Apr 2023 10:00:00 GMT', - 'Thu, 27 Apr 2023 10:00:00 GMT', - ]; - - if (isMysql(context)) { - expectedDateTimeWithoutTz[1] = 'Thu, 27 Apr 2023 04:30:00 GMT'; - expectedDateTimeWithTz[1] = 'Thu, 27 Apr 2023 04:30:00 GMT'; + let expectedDateTimeWithoutTz = []; + let expectedDateTimeWithTz = []; + + if (isSqlite(context)) { + expectedDateTimeWithoutTz = [ + '2023-04-27 10:00:00', + '2023-04-27 10:00:00+05:30', + `2023-04-27 10:00:00${formattedOffset}`, + ]; + expectedDateTimeWithTz = [ + '2023-04-27 10:00:00', + '2023-04-27 10:00:00+05:30', + `2023-04-27 10:00:00${formattedOffset}`, + ]; + } else if (isPg(context)) { + expectedDateTimeWithoutTz = ['2023-04-27 10:00:00', '2023-04-27 10:00:00', '2023-04-27 10:00:00']; + expectedDateTimeWithTz = [ + '2023-04-27T10:00:00.000Z', + '2023-04-27T04:30:00.000Z', + new Date('2023-04-27T10:00:00').toISOString(), + ]; + } else if (isMysql(context)) { + expectedDateTimeWithoutTz = ['2023-04-27 10:00:00', '2023-04-27 04:30:00', '2023-04-27 10:00:00']; + expectedDateTimeWithTz = ['2023-04-27 10:00:00', '2023-04-27 04:30:00', '2023-04-27 10:00:00']; } - // convert to ISO string, skip seconds part or reset seconds to 00 - dateTimeWithoutTz = dateTimeWithoutTz.map(dateTimeStr => { - const dateObj = new Date(dateTimeStr); - dateObj.setSeconds(0); - dateObj.setMinutes(dateObj.getMinutes() - timezoneOffset); - return dateObj.toUTCString(); - }); - dateTimeWithTz = dateTimeWithTz.map(dateTimeStr => { - const dateObj = new Date(dateTimeStr); - dateObj.setSeconds(0); - dateObj.setMinutes(dateObj.getMinutes() - timezoneOffset); - return dateObj.toUTCString(); - }); + // reset seconds to 00 using string functions in dateTimeWithoutTz + dateTimeWithoutTz = dateTimeWithoutTz.map( + dateTimeString => dateTimeString.substring(0, 17) + '00' + dateTimeString.substring(19) + ); + dateTimeWithTz = dateTimeWithTz.map( + dateTimeString => dateTimeString.substring(0, 17) + '00' + dateTimeString.substring(19) + ); - // console.log(dateTimeWithoutTz); - // console.log(dateTimeWithTz); + // console.log('dateTimeWithoutTz', dateTimeWithoutTz); + // console.log('dateTimeWithTz', dateTimeWithTz); expect(dateTimeWithoutTz).toEqual(expectedDateTimeWithoutTz); expect(dateTimeWithTz).toEqual(expectedDateTimeWithTz);