// 判断当前月份的总天数 const thisMonthLenth = (year, month) => { let len if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { len = 31 } else if (month == 4 || month == 6 || month == 9 || month == 11) { len = 30 } else if (month == 2) { if (((year % 4) == 0) && ((year % 100) != 0) || ((year % 400) == 0)) { len = 29 } else { len = 28 } } return len } // 获取最小的日期 const startDate = res => { if (res.length > 0) { let date = res[0] for (let i in res) { date = new Date(res[i]['date'].replace(/\-/g, "/")) < new Date(date['date'].replace(/\-/g, "/")) ? res[i] : date } return date } } // 判断是否是最大的日期 const isMaxDate = (date, data) => { let isSame = false let index = null if (data.length > 0) { for (let i in data) { if (new Date(date.replace(/\-/g, "/")).getTime() >= new Date(data[i]['date'].replace(/\-/g, "/")).getTime()) { isSame = true index = i break } } } return { isSame, index } } // 判断是否是相同的星期 const isSameWeek = (week, data) => { let isSame = false let index = null if (data.length > 0) { for (let i in data) { if (data[i]['week'] == week) { isSame = true index = i break } } } return { isSame, index } } // 判断是否是相同的星期 并且 传参日期要大于 当下日期 const isSameWeekTwo = (week, date, data) => { let isSame = false let index = null if (data.length > 0) { for (let i in data) { if (data[i]['week'] == week && new Date(date.replace(/\-/g, "/")).getTime() >= new Date(data[i]['date'].replace(/\-/g, "/")).getTime()) { isSame = true index = i break } } } return { isSame, index } } // 判断是否是相同的一天 const isSameDate = (date, data) => { let isSame = false let index = null if (data.length > 0) { for (let i in data) { if (data[i]['date'] == date) { isSame = true index = i break } } } return { isSame, index } } module.exports = { thisMonthLenth, startDate, isMaxDate, isSameWeek, isSameWeekTwo, isSameDate }