From 03473c816ea3b6dc7e202a7a18562705f3005c85 Mon Sep 17 00:00:00 2001 From: Pierre Brisorgueil Date: Mon, 23 Mar 2020 11:21:47 +0100 Subject: [PATCH] =?UTF-8?q?feat(typing):=20review=20hour=20conversion=20wo?= =?UTF-8?q?rk=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/helpers/typing/dates.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/helpers/typing/dates.js b/lib/helpers/typing/dates.js index 0143d94d8..cdf971864 100644 --- a/lib/helpers/typing/dates.js +++ b/lib/helpers/typing/dates.js @@ -35,7 +35,17 @@ exports.DATE_NEXT_DAY = (data) => { */ exports.HOUR = (data, params, object) => { let date; - if (params && params.length > 0) date = moment(_.get(object, params[0])).set('hour', Number(data)).format(); - date = moment(data).format(); + // check time + let time = {}; + if (params && params.length === 1) { + if (data.indexOf('h') > -1) time = { hour: data.split('h')[0], minute: data.split('h')[1] || 0, second: 0 }; + if (data.indexOf('H') > -1) time = { hour: data.split('H')[0], minute: data.split('H')[1] || 0, second: 0 }; + if (data.indexOf(':') > -1) time = { hour: data.split(':')[0], minute: data.split(':')[1] || 0, second: data.split(':')[2] || 0 }; + date = moment(_.get(object, params[0])) + .set('hour', Number(time.hour)) + .set('minute', Number(time.minute)) + .set('second', Number(time.second)) + .format(); + } else date = moment(data).format(); return date; };