riku
2023-08-29 71b1532d5a3609f3125e15fbe65e4b34bb6c4e8b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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}
}