fixed vn-mysql time offset
gitea/salix/test This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-02-25 10:04:11 +01:00
parent ac1e619b06
commit 5ec352b71a
1 changed files with 24 additions and 1 deletions

View File

@ -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);
}
};