From dd4f4e39fbe689c8624e1de6a05c974d7f50fec5 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Mon, 25 Feb 2019 11:40:50 +0100 Subject: [PATCH] date offset --- loopback/server/connectors/vn-mysql.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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); } } }