JS VUE 中 请假排除周末,包含半天可以设置

// 两个时间相差天数
const datedifference = (sDate1, sDate2) => { // sDate1和sDate2是2006-12-18格式
  let dateSpan,
    days,
    sDate = Date.parse(sDate1),
    eDate = Date.parse(sDate2);
  dateSpan = eDate - sDate;
  dateSpan = Math.abs(dateSpan);
  days = Math.floor(dateSpan / (24 * 3600 * 1000));
  return days;
};
const addDate = (date, days) => {
  const d = new Date(date);
  d.setDate(d.getDate() + days);
  const m = d.getMonth() + 1;
  return `${d.getFullYear()}-${m}-${d.getDate()}`;
};

const isWeekend = (date) => {
  const dd = new Date(date).getDay();
  if (dd === 6 || dd === 0) {
    return true;
  }
  return false;
};

const getHoliday = (sdate, edate, sAMOrPM, eAMOrPM) => {
// 时间格式 ‘2018-11-08 AM’ '2018-11-17 PM'  if (sdate && edate) {
    const num = datedifference(sdate, edate);
    const lastday = num % 7;
    let weeknum = 0,
      result = 0,
      weekDays = 0,
     halfWeekDay = 0,
      hlafDay = 0;
    if (sAMOrPM && eAMOrPM) {
     if (!isWeekend(sdate) && sAMOrPM === 'PM') {
      hlafDay = -0.5;
     }
     if (!isWeekend(edate) && eAMOrPM === 'AM') {
      hlafDay += 0.5;
     }
     if (!isWeekend(edate) && eAMOrPM === 'PM') {
      hlafDay += 1;
     }
     if (isWeekend(sdate) && sAMOrPM === 'AM') {
      halfWeekDay = 0;
     }
     if (isWeekend(sdate) && sAMOrPM === 'PM') {
      halfWeekDay = -0.5;
     }
     if (isWeekend(edate) && eAMOrPM === 'AM') {
      halfWeekDay = halfWeekDay + 0.5;
     }
     if (isWeekend(edate) && eAMOrPM === 'PM') {
      halfWeekDay = halfWeekDay + 1;
     }
    }
    if (num >= 7) {
      weeknum = parseInt(num / 7);
    }
    for (let i = 0; i < lastday; i++) {
      const dd = new Date(addDate(sdate, i)).getDay();
      if (dd !== 6 && dd !== 0) {
        result++;
      }
     if (dd === 6 || dd === 0) {
      weekDays++;
     }
    }
    return [(result + weeknum * 5 + hlafDay), (weekDays + weeknum * 2 + halfWeekDay)];
  }
  return 0;
};
export default {
  datedifference,
  addDate,
  isWeekend,
  getHoliday,
};

JS VUE 中 请假排除周末,包含半天可以设置_第1张图片

JS VUE 中 请假排除周末,包含半天可以设置_第2张图片VUE + VUX 手机端html

 

 

你可能感兴趣的:(VUX,VUE,JS)