Skip to content

Commit

Permalink
Rework switchover time implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Newbytee committed Aug 31, 2020
1 parent 862fd69 commit e0a4734
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ function init() {
applyDarkTheme();
}

updateDateObject();
createSlideout();
checkDeviceType(); // Check orientation fails if slideout hasn't been created, please keep them this order

Expand Down Expand Up @@ -340,16 +339,6 @@ function showSnackbar(text) {
});
}

function updateDateObject() {
const switchoverTime = CONFIG.getVar("switchoverTime");

const NOW_DATE = new Date();
const DATE_AND_TIME_ARR = switchoverTime.split(":");

DATE.setHours(NOW_DATE.getHours() + parseInt(DATE_AND_TIME_ARR[0]));
DATE.setMinutes(NOW_DATE.getMinutes() + parseInt(DATE_AND_TIME_ARR[1]));
}

function resizeNeoschedule() {
checkDeviceType();

Expand Down Expand Up @@ -490,11 +479,34 @@ function setupNeoschedule() {

if (isMobile) {
SUBMIT_BUTTON.textContent = "Visa";
if (DATE.getDay() < 6) {
DAY_DROPDOWN.selectedIndex = DATE.getDay() === 0 ? 1 : DATE.getDay();

const currentDay = DATE.getDay();

if (currentDay < 6) {
DAY_DROPDOWN.selectedIndex = currentDay === 0 ? 1 : currentDay;
} else {
DAY_DROPDOWN.selectedIndex = 1;
}

const [
switchoverHourString,
switchoverMinuteString
] = CONFIG.getVar("switchoverTime").split(":");

const switchoverHour = parseInt(switchoverHourString);
const switchoverMinute = parseInt(switchoverMinuteString);

const currentHour = DATE.getHours();

if (
!((switchoverHour === currentHour &&
switchoverMinute >= DATE.getMinutes()) ||
switchoverHour > currentHour) &&
currentDay !== 0 &&
currentDay !== 6
) {
DAY_DROPDOWN.selectedIndex++;
}
} else {
SUBMIT_BUTTON.textContent = "Visa schema";
DAY_DROPDOWN.selectedIndex = 0;
Expand Down

0 comments on commit e0a4734

Please sign in to comment.