Browse Source

test: timezone converstions to utc

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
pull/5505/head
Raju Udava 2 years ago
parent
commit
62ce87658b
  1. 50
      tests/playwright/tests/db/timezone.spec.ts

50
tests/playwright/tests/db/timezone.spec.ts

@ -485,15 +485,15 @@ function getDateTimeInLocalTimeZone(dateString: string) {
function getDateTimeInUTCTimeZone(dateString: string) { function getDateTimeInUTCTimeZone(dateString: string) {
// create a Date object with the input string // create a Date object with the input string
// assumes local system timezone
const date = new Date(dateString); const date = new Date(dateString);
// get the timezone offset in minutes and convert to milliseconds // get the timezone offset in minutes and convert to milliseconds
// subtract the offset from the provided time in milliseconds for IST // subtract the offset from the provided time in milliseconds for IST
const offsetMs = date.getTimezoneOffset() * 60 * 1000; // const offsetMs = date.getTimezoneOffset() * 60 * 1000;
// adjust the date by the offset // adjust the date by the offset
const adjustedDate = new Date(date.getTime() + offsetMs); // const adjustedDate = new Date(date.getTime() + offsetMs);
const adjustedDate = new Date(date.getTime());
// format the adjusted date as a string in the desired format // format the adjusted date as a string in the desired format
const outputString = adjustedDate.toISOString().slice(0, 19).replace('T', ' '); const outputString = adjustedDate.toISOString().slice(0, 19).replace('T', ' ');
@ -524,11 +524,11 @@ test.describe.serial('External DB - DateTime column', async () => {
// with +HH:MM information, display value is converted to browser timezone // with +HH:MM information, display value is converted to browser timezone
// SQLite doesn't have with & without timezone fields; both are same in this case // SQLite doesn't have with & without timezone fields; both are same in this case
DatetimeWithoutTz: [ DatetimeWithoutTz: [
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+00:00'), getDateTimeInLocalTimeZone(`2023-04-27 10:00:00`),
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+05:30'), getDateTimeInLocalTimeZone('2023-04-27 10:00:00+05:30'),
], ],
DatetimeWithTz: [ DatetimeWithTz: [
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+00:00'), getDateTimeInLocalTimeZone(`2023-04-27 10:00:00`),
getDateTimeInLocalTimeZone('2023-04-27 10:00:00+05:30'), getDateTimeInLocalTimeZone('2023-04-27 10:00:00+05:30'),
], ],
}, },
@ -692,6 +692,15 @@ test.describe.serial('External DB - DateTime column', async () => {
await dashboard.treeView.openBase({ title: 'datetimetable' }); await dashboard.treeView.openBase({ title: 'datetimetable' });
await dashboard.treeView.openTable({ title: 'MyTable' }); await dashboard.treeView.openTable({ title: 'MyTable' });
if (isSqlite(context)) {
expectedDisplayValues['sqlite'].DatetimeWithoutTz[0] = getDateTimeInLocalTimeZone(
`2023-04-27 10:00:00${formattedOffset}`
);
expectedDisplayValues['sqlite'].DatetimeWithTz[0] = getDateTimeInLocalTimeZone(
`2023-04-27 10:00:00${formattedOffset}`
);
}
// display value for datetime column without tz should be same as stored value // display value for datetime column without tz should be same as stored value
// display value for datetime column with tz should be converted to browser timezone (HK in this case) // display value for datetime column with tz should be converted to browser timezone (HK in this case)
await dashboard.grid.cell.verifyDateCell({ await dashboard.grid.cell.verifyDateCell({
@ -755,36 +764,36 @@ test.describe.serial('External DB - DateTime column', async () => {
if (isSqlite(context)) { if (isSqlite(context)) {
expectedDateTimeWithoutTz = [ expectedDateTimeWithoutTz = [
'2023-04-27 10:00:00+00:00', getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
'2023-04-27 10:00:00+05:30', getDateTimeInUTCTimeZone('2023-04-27 10:00:00+05:30'),
getDateTimeInUTCTimeZone('2023-04-27 10:00:00+00:00'), getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
]; ];
expectedDateTimeWithTz = [ expectedDateTimeWithTz = [
'2023-04-27 10:00:00+00:00', getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
'2023-04-27 10:00:00+05:30', getDateTimeInUTCTimeZone('2023-04-27 10:00:00+05:30'),
getDateTimeInUTCTimeZone('2023-04-27 10:00:00+00:00'), getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
]; ];
} else if (isPg(context)) { } else if (isPg(context)) {
expectedDateTimeWithoutTz = [ expectedDateTimeWithoutTz = [
'2023-04-27 10:00:00+00:00', '2023-04-27 10:00:00+00:00',
'2023-04-27 10:00:00+00:00', '2023-04-27 10:00:00+00:00',
getDateTimeInUTCTimeZone('2023-04-27 10:00:00+00:00'), getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
]; ];
expectedDateTimeWithTz = [ expectedDateTimeWithTz = [
'2023-04-27 10:00:00+00:00', '2023-04-27 10:00:00+00:00',
'2023-04-27 04:30:00+00:00', '2023-04-27 04:30:00+00:00',
getDateTimeInUTCTimeZone('2023-04-27 10:00:00+00:00'), getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
]; ];
} else if (isMysql(context)) { } else if (isMysql(context)) {
expectedDateTimeWithoutTz = [ expectedDateTimeWithoutTz = [
'2023-04-27 10:00:00+00:00', '2023-04-27 10:00:00+00:00',
'2023-04-27 04:30:00+00:00', '2023-04-27 04:30:00+00:00',
getDateTimeInUTCTimeZone('2023-04-27 10:00:00+00:00'), getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
]; ];
expectedDateTimeWithTz = [ expectedDateTimeWithTz = [
'2023-04-27 10:00:00+00:00', '2023-04-27 10:00:00+00:00',
'2023-04-27 04:30:00+00:00', '2023-04-27 04:30:00+00:00',
getDateTimeInUTCTimeZone('2023-04-27 10:00:00+00:00'), getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
]; ];
} }
@ -840,6 +849,13 @@ test.describe('Ext DB MySQL : DB Timezone configured as HKT', () => {
return; return;
} }
// 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')}`;
// connect after timezone is set // connect after timezone is set
await connectToExtDb(context); await connectToExtDb(context);
@ -909,12 +925,12 @@ test.describe('Ext DB MySQL : DB Timezone configured as HKT', () => {
const expectedDateTimeWithoutTz = [ const expectedDateTimeWithoutTz = [
'2023-04-27 02:00:00+00:00', '2023-04-27 02:00:00+00:00',
'2023-04-27 04:30:00+00:00', '2023-04-27 04:30:00+00:00',
getDateTimeInUTCTimeZone('2023-04-27 10:00:00+00:00'), getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
]; ];
const expectedDateTimeWithTz = [ const expectedDateTimeWithTz = [
'2023-04-27 02:00:00+00:00', '2023-04-27 02:00:00+00:00',
'2023-04-27 04:30:00+00:00', '2023-04-27 04:30:00+00:00',
getDateTimeInUTCTimeZone('2023-04-27 10:00:00+00:00'), getDateTimeInUTCTimeZone(`2023-04-27 10:00:00${formattedOffset}`),
]; ];
// reset seconds to 00 using string functions in dateTimeWithoutTz // reset seconds to 00 using string functions in dateTimeWithoutTz

Loading…
Cancel
Save