diff --git a/loopback/server/connectors/vn-mysql.js b/loopback/server/connectors/vn-mysql.js index dee523be7..efe859a06 100644 --- a/loopback/server/connectors/vn-mysql.js +++ b/loopback/server/connectors/vn-mysql.js @@ -24,6 +24,18 @@ class VnMySQL extends MySQL { } } + fromColumnValue(prop, val) { + if (val == null || !prop || prop.type !== Date) + return MySQL.prototype.fromColumnValue.call(this, prop, val); + + let date = new Date(val); + let locale = new Date(val); + let offset = locale.getTimezoneOffset() * 60000; + date.setTime(date.getTime() + offset); + + return date; + } + /** * Promisified version of execute(). * @@ -34,6 +46,16 @@ class VnMySQL extends MySQL { * @return {Promise} The operation promise */ executeP(query, params, options = {}, cb) { + if (params) { + for (let param of params) { + if (param && typeof param.getMonth === 'function') { + let locale = new Date(param); + let offset = locale.getTimezoneOffset() * 60000; + param.setTime(param.getTime() - offset); + } + } + } + return new Promise((resolve, reject) => { this.execute(query, params, options, (error, response) => { if (cb) @@ -230,11 +252,12 @@ exports.initialize = function initialize(dataSource, callback) { dataSource.EnumFactory = EnumFactory; - if (callback) + if (callback) { if (dataSource.settings.lazyConnect) { process.nextTick(function() { callback(); }); } else dataSource.connector.connect(callback); + } };