Skip to content

Commit

Permalink
[misc] connection correction after #a862d8dbf7d9727d34fe4bb4f75f08461…
Browse files Browse the repository at this point in the history
…02d6ea3
  • Loading branch information
rusher committed Jul 5, 2022
1 parent ec3924c commit 723fe8e
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions lib/connection.js
Expand Up @@ -613,31 +613,30 @@ class Connection extends EventEmitter {
checkServerTimezone() {
if (this.opts.timezone === 'auto') {
return new Promise(
this.query.bind(this, new CommandParameter('SELECT @@system_time_zone stz, @@time_zone tz')),
(res) => {
const serverTimezone = res[0].tz === 'SYSTEM' ? res[0].stz : res[0].tz;
const serverZone = moment.tz.zone(serverTimezone);
if (serverZone) {
const localTz = moment.tz.guess();
if (serverTimezone === localTz) {
//db server and client use same timezone, avoid any conversion
this.opts.tz = null;
} else {
this.opts._localTz = localTz;
this.opts.tz = serverTimezone;
}
this.query.bind(this, new CommandParameter('SELECT @@system_time_zone stz, @@time_zone tz'))
).then((res) => {
const serverTimezone = res[0].tz === 'SYSTEM' ? res[0].stz : res[0].tz;
const serverZone = moment.tz.zone(serverTimezone);
if (serverZone) {
const localTz = moment.tz.guess();
if (serverTimezone === localTz) {
//db server and client use same timezone, avoid any conversion
this.opts.tz = null;
} else {
const err = Errors.createFatalError(
`Automatic timezone setting fails. Server timezone '${serverTimezone}' doesn't have a corresponding IANA timezone. Option timezone must be set according to server timezone`,
Errors.ER_WRONG_AUTO_TIMEZONE,
this.info
);
if (this.opts.logger.error) this.opts.logger.error(err);
return Promise.reject(err);
this.opts._localTz = localTz;
this.opts.tz = serverTimezone;
}
return Promise.resolve();
} else {
const err = Errors.createFatalError(
`Automatic timezone setting fails. Server timezone '${serverTimezone}' doesn't have a corresponding IANA timezone. Option timezone must be set according to server timezone`,
Errors.ER_WRONG_AUTO_TIMEZONE,
this.info
);
if (this.opts.logger.error) this.opts.logger.error(err);
return Promise.reject(err);
}
);
return Promise.resolve();
});
}
if (this.opts.tz && !this.opts.skipSetTimezone) {
let tz = this.opts.tz;
Expand Down

0 comments on commit 723fe8e

Please sign in to comment.