🐛 Skip weekend in navigation
This commit is contained in:
@ -30,14 +30,17 @@ function slideChange(swiper) {
|
||||
const activeSlide = swiper.activeIndex;
|
||||
if (activeSlide == loadedDates.value.length - 1) {
|
||||
const lastDate = loadedDates.value[loadedDates.value.length - 1];
|
||||
loadedDates.value.push(calculateDate(lastDate, 1));
|
||||
loadedDates.value.push(getDateSkippingWeekend(calculateDate(lastDate, 1)));
|
||||
}
|
||||
}
|
||||
function slideChangeEnd(swiper) {
|
||||
const activeSlide = swiper.activeIndex;
|
||||
if (activeSlide == 0) {
|
||||
const lastDate = loadedDates.value[0];
|
||||
loadedDates.value = [calculateDate(lastDate, -1), ...loadedDates.value];
|
||||
loadedDates.value = [
|
||||
getDateSkippingWeekend(calculateDate(lastDate, -1)),
|
||||
...loadedDates.value,
|
||||
];
|
||||
swiper.slideTo(activeSlide + 1, 0);
|
||||
}
|
||||
}
|
||||
@ -62,12 +65,23 @@ function slideToDate(date) {
|
||||
// Watch for slide change instructions
|
||||
watch(changeDay, (change) => {
|
||||
if (change == 0) return;
|
||||
slideToDate(calculateDate(selectedDate.value, change));
|
||||
const calculatedDate = calculateDate(selectedDate.value, change);
|
||||
slideToDate(getDateSkippingWeekend(calculatedDate));
|
||||
changeDay.value = 0;
|
||||
});
|
||||
watch(changeDate, (date) => {
|
||||
slideToDate(new Date(date.setUTCHours(0, 0, 0, 0)));
|
||||
});
|
||||
|
||||
function getDateSkippingWeekend(date) {
|
||||
var calculatedDate = date;
|
||||
// Skip weekend
|
||||
if (calculatedDate.getDay() == 6)
|
||||
calculatedDate = new Date(calculatedDate.getTime() + 86400000 * 2);
|
||||
if (calculatedDate.getDay() == 0)
|
||||
calculatedDate = new Date(calculatedDate.getTime() - 86400000 * 2);
|
||||
return calculatedDate;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
Reference in New Issue
Block a user