From c11d603ff96f1c987f963245c22d8d2ffa7fe62e Mon Sep 17 00:00:00 2001 From: afonsopacifer Date: Tue, 25 Jun 2019 13:38:46 -0300 Subject: [PATCH] fix: Remove dayjs and add vanilla time formatter --- src/utils/transformToScheduleHour.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/utils/transformToScheduleHour.js b/src/utils/transformToScheduleHour.js index b989d8b..253b1dd 100644 --- a/src/utils/transformToScheduleHour.js +++ b/src/utils/transformToScheduleHour.js @@ -1,15 +1,31 @@ -import dayjs from 'dayjs'; +// import dayjs from 'dayjs'; + +const adjustGMT = (hours) => { + const localTime = hours - 3; + const withZero = localTime.toString().length === 1 ? `0${localTime}` : localTime; + return withZero; +}; + +const dateToTime = (date) => { + const fullTime = date.split('T')[1]; + const time = fullTime.substring(0, 5); + const hours = time.split(':')[0]; + const minutes = time.split(':')[1]; + + return `${adjustGMT(hours)}:${minutes}`; +}; /** * @param {string} start * @param {string} [end] * @retuns {string} */ + const transformToScheduleHour = (start, end = null) => { - start = dayjs(start).format('HH:mm'); + start = dateToTime(start); if (end) { - end = dayjs(end).format('HH:mm'); + end = dateToTime(end); } return start + (end ? ` - ${end}` : '');