export function useCommonFunction(){
|
/**
|
* description:判断起始时间跨度是否超过1个月
|
* @param: 开始时间,结束时间
|
* @createTime:2023-08-18
|
* @returns:超过一个月返回true,不超过一个月则返回false
|
*/
|
function isExceedOneMonth(dateStr1, dateStr2) {
|
// 超过一个月,返回True,否则返回False
|
// 将日期字符串转为日期对象
|
const date1 = new Date(dateStr1);
|
const date2 = new Date(dateStr2);
|
|
// 获取两个日期的年、月、日
|
const year1 = date1.getFullYear();
|
const month1 = date1.getMonth();
|
const day1 = date1.getDate();
|
|
const year2 = date2.getFullYear();
|
const month2 = date2.getMonth();
|
const day2 = date2.getDate();
|
console.log(month1, month2);
|
|
// 判断两个日期是否相差一个月
|
if (year1 === year2) {
|
// 年份相等,比较月份差值
|
if (Math.abs(month1 - month2) === 1) {
|
// 月份差值为1,还需要判断具体日期
|
if (
|
(month1 < month2 && day1 < day2) ||
|
(month1 > month2 && day1 > day2)
|
) {
|
return true;
|
}
|
}
|
} else if (Math.abs(year1 - year2) === 1) {
|
// 年份差值为1,比较月份和日期
|
if (
|
(year1 < year2 && month1 === 11 && month2 === 0 && day1 < day2) ||
|
(year1 > year2 && month1 === 0 && month2 === 11 && day1 > day2)
|
) {
|
return true;
|
}
|
}
|
|
// 默认返回false,表示两个日期字符串不相差一个月
|
return false;
|
}
|
|
/**
|
* description:百分号比较大小
|
* @param: a是否大于b
|
* @returns:大于,则返回true。否则返回false
|
*/
|
function cmpp(a, b) {
|
return Number(a.replace('%', '')) > Number(b.replace('%', ''));
|
}
|
|
return {isExceedOneMonth,cmpp}
|
}
|