Skip to content

Commit

Permalink
fix(mariadb): named timezone support (#10705)
Browse files Browse the repository at this point in the history
  • Loading branch information
javiertury authored and sushantdhiman committed Apr 8, 2019
1 parent d6daaf1 commit 175da2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/dialects/mariadb/connection-manager.js
Expand Up @@ -54,13 +54,18 @@ class ConnectionManager extends AbstractConnectionManager {
* @private
*/
connect(config) {
// Named timezone is not supported in mariadb, convert to offset
let tzOffset = this.sequelize.options.timezone;
tzOffset = /\//.test(tzOffset) ? momentTz.tz(tzOffset).format('Z')
: tzOffset;

const connectionConfig = {
host: config.host,
port: config.port,
user: config.username,
password: config.password,
database: config.database,
timezone: this.sequelize.options.timezone,
timezone: tzOffset,
typeCast: ConnectionManager._typecast.bind(this),
bigNumberStrings: false,
supportBigNumbers: true,
Expand All @@ -73,10 +78,6 @@ class ConnectionManager extends AbstractConnectionManager {

if (!this.sequelize.config.keepDefaultTimezone) {
// set timezone for this connection
// but named timezone are not directly supported in mariadb, so get its offset first
let tzOffset = this.sequelize.options.timezone;
tzOffset = /\//.test(tzOffset) ? momentTz.tz(tzOffset).format('Z')
: tzOffset;
if (connectionConfig.initSql) {
if (!Array.isArray(
connectionConfig.initSql)) {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/timezone.test.js
Expand Up @@ -38,7 +38,7 @@ if (dialect !== 'sqlite') {
});
});

if (dialect === 'mysql') {
if (dialect === 'mysql' || dialect === 'mariadb') {
it('handles existing timestamps', function() {
const NormalUser = this.sequelize.define('user', {}),
TimezonedUser = this.sequelizeWithTimezone.define('user', {});
Expand Down

0 comments on commit 175da2d

Please sign in to comment.