diff --git a/loopback/server/connectors/vn-mysql.js b/loopback/server/connectors/vn-mysql.js index efe859a06..051d8738f 100644 --- a/loopback/server/connectors/vn-mysql.js +++ b/loopback/server/connectors/vn-mysql.js @@ -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); } } }