date offset
gitea/salix/test This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-02-25 11:40:50 +01:00
parent a389ca46a2
commit dd4f4e39fb
1 changed files with 8 additions and 1 deletions

View File

@ -36,6 +36,11 @@ class VnMySQL extends MySQL {
return date;
}
isIsoDate(dateString) {
let isoRegexp = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/g;
return isoRegexp.test(dateString);
}
/**
* Promisified version of execute().
*
@ -48,10 +53,12 @@ class VnMySQL extends MySQL {
executeP(query, params, options = {}, cb) {
if (params) {
for (let param of params) {
if (param && typeof param.getMonth === 'function') {
if (param && typeof param.getMonth === 'function' || this.isIsoDate(param)) {
if (this.isIsoDate(param)) param = new Date(param);
let locale = new Date(param);
let offset = locale.getTimezoneOffset() * 60000;
param.setTime(param.getTime() - offset);
console.log(param);
}
}
}