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