getmonthlist
Version:
Input the month and year, Output the data for the current month
39 lines (32 loc) • 1.19 kB
JavaScript
// [{year month date week}]
function getMonthList(year, month) {
function getCountDays() {
const curDate = new Date()
const curWeek = new Date()
const month_Date = (month || month === 0) ? month + 1 : curDate.getMonth() + 1
const month_Week = (month || month === 0) ? month : curDate.getMonth()
const month_ = month || curDate.getMonth()
const year_ = year || curDate.getFullYear()
curDate.setFullYear(year_)
curDate.setMonth(month_Date)
curDate.setDate(0)
curWeek.setFullYear(year_)
curWeek.setMonth(month_Week)
curWeek.setDate(1)
return { curYear: year_, curMonth: month_, curDate, curWeek }
}
function getEveryDay() {
const dayArray = []
const curDate = getCountDays().curDate.getDate()
const curWeek = getCountDays().curWeek
const curMonth = getCountDays().curMonth
const curYear = getCountDays().curYear
for (let k = 1; k <= curDate; k++) {
curWeek.setDate(k)
dayArray.push({ year: curYear, month: curMonth, day: k, week: curWeek.getDay() || 7 })
}
return dayArray
}
return getEveryDay()
}
export default getMonthList