Skip to content

Commit

Permalink
fix jumpDate
Browse files Browse the repository at this point in the history
  • Loading branch information
uvarov-frontend committed Sep 19, 2023
1 parent bac8193 commit 6c1a336
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package/src/scripts/methods/changeMonth.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { IVanillaCalendar } from '../../types';
import generateDate from '../helpers/generateDate';
import controlArrows from './controlArrows';
import createDays from './createDays';
import showMonth from './showMonth';
import showYear from './showYear';

const changeMonth = (self: IVanillaCalendar, route: string | undefined) => {
if (self.selectedMonth === undefined || self.selectedYear === undefined) return;
const jumpDate = new Date(self.selectedYear, self.selectedMonth, 1);
const jumpDate = new Date(generateDate(new Date(self.selectedYear, self.selectedMonth, 1)));

switch (route) {
case 'prev':
Expand Down
15 changes: 11 additions & 4 deletions package/src/scripts/methods/controlArrows.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IVanillaCalendar } from '../../types';
import generateDate from '../helpers/generateDate';

const controlArrows = (self: IVanillaCalendar) => {
if (!['default', 'multiple', 'year'].includes(self.currentType)) return;
Expand All @@ -11,17 +12,23 @@ const controlArrows = (self: IVanillaCalendar) => {
const defaultControl = () => {
if (!self.dateMin || !self.dateMax) return;

const jumpDateMin = new Date(self.selectedYear as number, self.selectedMonth as number, 1);
const jumpDateMax = new Date(self.selectedYear as number, self.selectedMonth as number, 1);
const jumpDateMin = new Date(generateDate(new Date(self.selectedYear as number, self.selectedMonth as number, 1)));
const jumpDateMax = new Date(jumpDateMin.getTime());
jumpDateMin.setMonth(jumpDateMin.getMonth() - self.jumpMonths);
jumpDateMax.setMonth(jumpDateMax.getMonth() + self.jumpMonths);

if (jumpDateMin < self.dateMin || !self.settings.selection.month) {
if (!self.settings.selection.month
|| jumpDateMin.getFullYear() < self.dateMin.getFullYear()
|| (jumpDateMin.getFullYear() === self.dateMin.getFullYear()
&& (jumpDateMin.getMonth() < self.dateMin.getMonth()))) {
arrowPrev.style.visibility = 'hidden';
} else {
arrowPrev.style.visibility = '';
}
if (jumpDateMax > self.dateMax || !self.settings.selection.month) {
if (!self.settings.selection.month
|| jumpDateMax.getFullYear() > self.dateMax.getFullYear()
|| (jumpDateMax.getFullYear() === self.dateMax.getFullYear()
&& jumpDateMax.getMonth() > self.dateMax.getMonth())) {
arrowNext.style.visibility = 'hidden';
} else {
arrowNext.style.visibility = '';
Expand Down

0 comments on commit 6c1a336

Please sign in to comment.