修改日历组件
This commit is contained in:
@@ -29,6 +29,40 @@ export const getDate = (date: string): string => {
|
||||
return dayjs(date).format('YYYY年MM月DD日')
|
||||
}
|
||||
|
||||
export const getDay = (date?: string | Date): string => {
|
||||
if (!date) {
|
||||
return dayjs().format('YYYY-MM-DD')
|
||||
}
|
||||
return dayjs(date).format('YYYY-MM-DD')
|
||||
}
|
||||
|
||||
export const getMonth = (date?: string | Date): string => {
|
||||
if (!date) {
|
||||
return dayjs().format('MM月 YYYY')
|
||||
}
|
||||
return dayjs(date).format('MM月 YYYY')
|
||||
}
|
||||
|
||||
export const getWeekend = (date?: string | Date): [Date, Date] => {
|
||||
const today = dayjs(date);
|
||||
const currentDayOfWeek = today.day();
|
||||
console.log('currentDayOfWeek', currentDayOfWeek)
|
||||
const saturdayOffset = 6 - currentDayOfWeek
|
||||
const sundayOffset = 7 - currentDayOfWeek
|
||||
const sat = today.add(saturdayOffset, 'day')
|
||||
const sun = today.add(sundayOffset, 'day')
|
||||
return [sat.toDate(), sun.toDate()]
|
||||
}
|
||||
|
||||
export const getWeekendOfCurrentWeek = (days = 7): Date[] => {
|
||||
const dayList: Date[] = [];
|
||||
for (let i = 0; i < days; i++) {
|
||||
const day = dayjs().add(i, 'day').toDate()
|
||||
dayList.push(day)
|
||||
}
|
||||
return dayList
|
||||
}
|
||||
|
||||
export const getTime = (time: string): string => {
|
||||
const timeObj = dayjs(time)
|
||||
const hour = timeObj.hour()
|
||||
|
||||
Reference in New Issue
Block a user