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

Fix safari "Invalid Date" error #4

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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