From fab15857d2f55deca26d5b7440ebe6c9c83ff69a Mon Sep 17 00:00:00 2001 From: rusher Date: Wed, 10 May 2023 09:04:00 +0000 Subject: [PATCH] [misc] correct UTC timezone for auto timezone setting --- lib/connection.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/connection.js b/lib/connection.js index 073143ab..530341b2 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -30,8 +30,8 @@ const { Status } = require('./const/connection_status'); const CommandParameter = require('./command-parameter'); const LruPrepareCache = require('./lru-prepare-cache'); -const convertFixedTime = function (tz) { - if (tz === 'Etc/UTC' || tz === 'Z') { +const convertFixedTime = function (tz, conn) { + if (tz === 'UTC' || tz === 'Etc/UTC' || tz === 'Z' || tz === 'Etc/GMT') { return '+00:00'; } else if (tz.startsWith('Etc/GMT') || tz.startsWith('GMT')) { let tzdiff; @@ -50,7 +50,7 @@ const convertFixedTime = function (tz) { throw Errors.createFatalError( `Automatic timezone setting fails. wrong Server timezone '${tz}' conversion to +/-HH:00 conversion.`, Errors.ER_WRONG_AUTO_TIMEZONE, - this.info + conn.info ); } return (negate ? '-' : '+') + (diff >= 10 ? diff : '0' + diff) + ':00'; @@ -591,7 +591,7 @@ class Connection extends EventEmitter { for (let j = 0; j < paramLen; j++) { const val = row[j]; if ( - val !== null && + val != null && typeof val === 'object' && typeof val.pipe === 'function' && typeof val.read === 'function' @@ -607,7 +607,7 @@ class Connection extends EventEmitter { for (let j = 0; j < keys.length; j++) { const val = row[keys[j]]; if ( - val !== null && + val != null && typeof val === 'object' && typeof val.pipe === 'function' && typeof val.read === 'function' @@ -658,6 +658,7 @@ class Connection extends EventEmitter { * @private */ handleTimezone() { + const conn = this; if (this.opts.timezone === 'local') this.opts.timezone = undefined; if (this.opts.timezone === 'auto') { return new Promise( @@ -665,17 +666,17 @@ class Connection extends EventEmitter { ).then((res) => { const serverTimezone = res[0].tz === 'SYSTEM' ? res[0].stz : res[0].tz; const localTz = Intl.DateTimeFormat().resolvedOptions().timeZone; - if (serverTimezone === localTz || convertFixedTime(serverTimezone) === convertFixedTime(localTz)) { + if (serverTimezone === localTz || convertFixedTime(serverTimezone, conn) === convertFixedTime(localTz, conn)) { //server timezone is identical to client tz, skipping setting this.opts.timezone = localTz; return Promise.resolve(); } - return this._setSessionTimezone(convertFixedTime(localTz)); + return this._setSessionTimezone(convertFixedTime(localTz, conn)); }); } if (this.opts.timezone) { - return this._setSessionTimezone(convertFixedTime(this.opts.timezone)); + return this._setSessionTimezone(convertFixedTime(this.opts.timezone, conn)); } return Promise.resolve(); }