fix(Calendar): initial date incorrect (#8696)

* fix(Calendar): initial date incorrect

* feat(Calendar): add getToday function in utils
This commit is contained in:
nemo-shen 2021-05-13 09:21:15 +08:00 committed by GitHub
parent 3f7427b771
commit e6ca3270ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -24,6 +24,7 @@ import {
cloneDates, cloneDates,
getPrevDay, getPrevDay,
getNextDay, getNextDay,
getToday,
compareDay, compareDay,
calcDateNum, calcDateNum,
compareMonth, compareMonth,
@ -88,13 +89,13 @@ export default defineComponent({
minDate: { minDate: {
type: Date, type: Date,
validator: isDate, validator: isDate,
default: () => new Date(), default: getToday,
}, },
maxDate: { maxDate: {
type: Date, type: Date,
validator: isDate, validator: isDate,
default: () => { default: () => {
const now = new Date(); const now = getToday();
return new Date(now.getFullYear(), now.getMonth() + 6, now.getDate()); return new Date(now.getFullYear(), now.getMonth() + 6, now.getDate());
}, },
}, },
@ -129,7 +130,7 @@ export default defineComponent({
return defaultDate; return defaultDate;
} }
const now = new Date(); const now = getToday();
if (type === 'range') { if (type === 'range') {
if (!Array.isArray(defaultDate)) { if (!Array.isArray(defaultDate)) {

View File

@ -46,6 +46,11 @@ export function getDayByOffset(date: Date, offset: number) {
export const getPrevDay = (date: Date) => getDayByOffset(date, -1); export const getPrevDay = (date: Date) => getDayByOffset(date, -1);
export const getNextDay = (date: Date) => getDayByOffset(date, 1); export const getNextDay = (date: Date) => getDayByOffset(date, 1);
export const getToday = () => {
const today = new Date();
today.setHours(0, 0, 0, 0);
return today;
};
export function calcDateNum(date: [Date, Date]) { export function calcDateNum(date: [Date, Date]) {
const day1 = date[0].getTime(); const day1 = date[0].getTime();