dev
This commit is contained in:
parent
16b5fec12a
commit
8d887ff36b
|
|
@ -138,7 +138,7 @@
|
||||||
start="00:00"
|
start="00:00"
|
||||||
step="00:15"
|
step="00:15"
|
||||||
end="23:45"
|
end="23:45"
|
||||||
:min-time="getCurrentTime()"
|
:min-time="getCurrentTime(edit_data.date)"
|
||||||
placeholder="选择时间"
|
placeholder="选择时间"
|
||||||
style="width: 50%"
|
style="width: 50%"
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
export const formatDate = (date: Date|string): any => {
|
export const formatDate = (date: Date | string): any => {
|
||||||
if (date === undefined || date === null) {
|
if (date === undefined || date === null) {
|
||||||
return '-';
|
return '-';
|
||||||
}
|
}
|
||||||
|
|
@ -61,33 +61,48 @@ export const formatDateArray = (dates: Date[]): string[] => {
|
||||||
|
|
||||||
export const getToday = () => {
|
export const getToday = () => {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
return { start: formatDate(new Date(today.setHours(0, 0, 0, 0))), end: formatDate(new Date(today.setHours(23, 59, 59, 999))) };
|
return {
|
||||||
|
start: formatDate(new Date(today.setHours(0, 0, 0, 0))),
|
||||||
|
end: formatDate(new Date(today.setHours(23, 59, 59, 999)))
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getYesterday = () => {
|
export const getYesterday = () => {
|
||||||
const yesterday = new Date();
|
const yesterday = new Date();
|
||||||
yesterday.setDate(yesterday.getDate() - 1);
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
return { start: formatDate(new Date(yesterday.setHours(0, 0, 0, 0))), end: formatDate(new Date(yesterday.setHours(23, 59, 59, 999))) };
|
return {
|
||||||
|
start: formatDate(new Date(yesterday.setHours(0, 0, 0, 0))),
|
||||||
|
end: formatDate(new Date(yesterday.setHours(23, 59, 59, 999)))
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTomorrow = () => {
|
export const getTomorrow = () => {
|
||||||
const tomorrow = new Date();
|
const tomorrow = new Date();
|
||||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||||
return { start: formatDate(new Date(tomorrow.setHours(0, 0, 0, 0))), end: formatDate(new Date(tomorrow.setHours(23, 59, 59, 999))) };
|
return {
|
||||||
|
start: formatDate(new Date(tomorrow.setHours(0, 0, 0, 0))),
|
||||||
|
end: formatDate(new Date(tomorrow.setHours(23, 59, 59, 999)))
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getThisWeek = () => {
|
export const getThisWeek = () => {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const startOfWeek = new Date(today.setDate(today.getDate() - today.getDay()));
|
const startOfWeek = new Date(today.setDate(today.getDate() - today.getDay()));
|
||||||
const endOfWeek = new Date(today.setDate(today.getDate() - today.getDay() + 6));
|
const endOfWeek = new Date(today.setDate(today.getDate() - today.getDay() + 6));
|
||||||
return { start: formatDate(new Date(startOfWeek.setHours(0, 0, 0, 0))), end: formatDate(new Date(endOfWeek.setHours(23, 59, 59, 999))) };
|
return {
|
||||||
|
start: formatDate(new Date(startOfWeek.setHours(0, 0, 0, 0))),
|
||||||
|
end: formatDate(new Date(endOfWeek.setHours(23, 59, 59, 999)))
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getThisMonth = () => {
|
export const getThisMonth = () => {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const startOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
|
const startOfMonth = new Date(today.getFullYear(), today.getMonth(), 1);
|
||||||
const endOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0);
|
const endOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0);
|
||||||
return { start: formatDate(new Date(startOfMonth.setHours(0, 0, 0, 0))), end: formatDate(new Date(endOfMonth.setHours(23, 59, 59, 999))) };
|
return {
|
||||||
|
start: formatDate(new Date(startOfMonth.setHours(0, 0, 0, 0))),
|
||||||
|
end: formatDate(new Date(endOfMonth.setHours(23, 59, 59, 999)))
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getDaysBetweenDates = (startDateStr: string, endDateStr: string): string[] => {
|
export const getDaysBetweenDates = (startDateStr: string, endDateStr: string): string[] => {
|
||||||
|
|
@ -119,7 +134,7 @@ export const getEndOfDay = (date: Date | string): string => {
|
||||||
dateDetail.setHours(23, 59, 59, 0); // 设置为当天 23:59:00
|
dateDetail.setHours(23, 59, 59, 0); // 设置为当天 23:59:00
|
||||||
return formatDate(dateDetail).slice(0, 19); //
|
return formatDate(dateDetail).slice(0, 19); //
|
||||||
};
|
};
|
||||||
export const getCurrentDate=()=> {
|
export const getCurrentDate = () => {
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const year = date.getFullYear();
|
const year = date.getFullYear();
|
||||||
// 月份从0开始,所以要加1
|
// 月份从0开始,所以要加1
|
||||||
|
|
@ -128,7 +143,7 @@ export const getCurrentDate=()=> {
|
||||||
return `${year}-${month}-${day}`;
|
return `${year}-${month}-${day}`;
|
||||||
}
|
}
|
||||||
//帮我写个方法获取前30天日期并返回
|
//帮我写个方法获取前30天日期并返回
|
||||||
export const getPrevious30Days=()=> {
|
export const getPrevious30Days = () => {
|
||||||
const dates = [];
|
const dates = [];
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
for (let i = 0; i < 31; i++) {
|
for (let i = 0; i < 31; i++) {
|
||||||
|
|
@ -136,13 +151,25 @@ export const getPrevious30Days=()=> {
|
||||||
date.setDate(currentDate.getDate() - i);
|
date.setDate(currentDate.getDate() - i);
|
||||||
dates.push(date.toISOString().slice(0, 10));
|
dates.push(date.toISOString().slice(0, 10));
|
||||||
}
|
}
|
||||||
return dates[dates.length-1];
|
return dates[dates.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取当前时间的时分
|
//获取当前时间的时分
|
||||||
export const getCurrentTime=()=> {
|
export const getCurrentTime = (date:any) => {
|
||||||
const currentDate = new Date();
|
const today = new Date();
|
||||||
const hours = currentDate.getHours();
|
const selectedDate =date ? new Date(date) : today;
|
||||||
const minutes = currentDate.getMinutes();
|
|
||||||
return `${hours}:${minutes}`;
|
// 判断是否是今天
|
||||||
}
|
const isToday =
|
||||||
|
selectedDate.getFullYear() === today.getFullYear() &&
|
||||||
|
selectedDate.getMonth() === today.getMonth() &&
|
||||||
|
selectedDate.getDate() === today.getDate();
|
||||||
|
|
||||||
|
if (isToday) {
|
||||||
|
// 如果是今天,返回当前时间如 "14:30"
|
||||||
|
return `${String(today.getHours()).padStart(2, '0')}:${String(today.getMinutes()).padStart(2, '0')}`;
|
||||||
|
} else {
|
||||||
|
// 如果不是今天,返回 null 或 undefined,表示不设置 min-time
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue