Skip to content
This repository was archived by the owner on Apr 17, 2022. It is now read-only.

Commit 075b83d

Browse files
committed
fix: Wrong month/year on second calendar with partial range in two-calendars mode
1 parent 44f9c06 commit 075b83d

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/Vue3DatePicker/components/composition/calendar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { computed, onMounted, Ref, ref, UnwrapRef, watch } from 'vue';
22
import { ICalendarDay, IMarker, InternalModuleValue, UseCalendar, VueEmit } from '../../interfaces';
33
import {
4+
addMonthsToDate,
45
getAddedDays,
56
getDateHours,
67
getDateMinutes,
@@ -372,7 +373,7 @@ export const useCalendar = (props: UseCalendar, emit: VueEmit): IUseCalendar =>
372373

373374
const handleNextMonthYear = (): void => {
374375
if (Array.isArray(modelValue.value) && modelValue.value.length === 2) {
375-
const date = new Date(modelValue.value[1]);
376+
const date = new Date(modelValue.value[1] ? modelValue.value[1] : addMonthsToDate(modelValue.value[0]));
376377
if ((monthNext.value === month.value && yearNext.value === year.value) || !props.twoCalendarsSolo) {
377378
const date = getNextYearMonth(month.value, year.value);
378379
monthNext.value = date.month;

src/Vue3DatePicker/utils/date-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ export const getNextYearMonth = (month: number, year: number): { month: number;
306306
return { month: getMonth(date), year: getYear(date) };
307307
};
308308

309+
export const addMonthsToDate = (date: Date | string, amount = 1): Date => addMonths(new Date(date), amount);
310+
309311
export const getWeekDay = (date: string | Date): number => {
310312
return getDay(new Date(date));
311313
};

0 commit comments

Comments
 (0)