fix(calendar): fix cannot select the same day on allow-same-day (#5193)

This commit is contained in:
landluck 2023-01-12 17:56:17 +08:00 committed by GitHub
parent e9d521a8d2
commit 231aa05e8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@ import Toast from '../toast/toast';
import { requestAnimationFrame } from '../common/utils';
const initialMinDate = getToday().getTime();
const initialMaxDate = (() => {
const now = getToday();
return new Date(
@ -26,6 +27,7 @@ const initialMaxDate = (() => {
now.getDate()
).getTime();
})();
const getTime = (date: Date | number) =>
date instanceof Date ? date.getTime() : date;
@ -194,7 +196,7 @@ VantComponent({
},
getInitialDate(defaultDate: number | number[] | null = null) {
const { type, minDate, maxDate } = this.data;
const { type, minDate, maxDate, allowSameDay } = this.data;
const now = getToday().getTime();
@ -210,10 +212,14 @@ VantComponent({
minDate,
getPrevDay(new Date(maxDate)).getTime()
);
const date = getTime(endDay || now);
const end = this.limitDateRange(
endDay || now,
getNextDay(new Date(minDate)).getTime()
date,
allowSameDay ? date : getNextDay(new Date(minDate)).getTime()
);
return [start, end];
}