Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
fix: Remove dayjs and add vanilla time formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
afonsopacifer authored and Keit Oliveira committed Jun 25, 2019
1 parent 99e1907 commit 4ebf8e4
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/utils/transformToScheduleHour.js
Original file line number Diff line number Diff line change
@@ -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}` : '');
Expand Down

0 comments on commit 4ebf8e4

Please sign in to comment.