Skip to content

Commit

Permalink
feat(typing): review hour conversion work ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreBrisorgueil committed Mar 23, 2020
1 parent c601325 commit 03473c8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/helpers/typing/dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit 03473c8

Please sign in to comment.