export let getWeek = (year, month) => {
	year = parseInt(year);
	month = parseInt(month);
	var d = new Date(year, month, 0);
	let maxDay = d.getDate();
	let arr = []
	for (let i = 1; i <= maxDay; i++) {
		let date = new Date(year + '/' + month + '/' + i)// '/'兼容ios
		let week = date.getDay()
		let weekStr = ""
		let isToday = 0
		let today = new Date(getToday()).getTime()
		let today2 = new Date(year + '-' + (month < 10 ? '0' + month : month) + '-' + (i < 10 ? '0' + i : i))
			.getTime()
		if (today === today2) {
			isToday = 1
		}
		arr.push({
			week: week,
			day: i,
			isToday: isToday
		})
	}
	return arr
}

export let getMonthMaxDay = (y, m) => {
	let maxDay = 30
	if(y&&m){
		maxDay= new Date(y, m, "0").getDate();
	}else{
		const d=new Date()
		maxDay= new Date( d.getFullYear(),d.getMonth()+1,0).getDate();
	}
	return maxDay
}
export let getToday = (y, m, d) => {
	let date = new Date()
	let year = date.getFullYear()
	let month = date.getMonth() < 9 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
	let day = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()
	let today = year + "-" + month + '-' + day
	let curMonth = year + "-" + month
	if (y && m) {
		return curMonth
	} else {
		return today
	}
}

export let getCurrentTime = () => {
	let date = new Date()
	let year = date.getFullYear()
	let month = date.getMonth() + 1
	let day = date.getDate()
	let h = date.getHours()
	let m = date.getMinutes()
	let s = date.getSeconds()
	let CurrentTime = year + "-" + (month < 10 ? '0' + month : month) + '-' + (day < 10 ? '0' + day : day) + ' ' + (
		h < 10 ? '0' + h : h) + ':' + (m < 10 ? '0' + m : m) + ':' + (s < 10 ? '0' + s : s)
	return CurrentTime
}

export let getdate = (time, tomorrow) => {
	let date = new Date(time)
	let year = date.getFullYear()
	let month = date.getMonth() < 9 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
	let day = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()
	if (tomorrow === 1) {
		day = date.getDate() < 9 ? '0' + (date.getDate() + 1) : date.getDate() + 1
	}
	let d = year + "-" + month + '-' + day
	return d
}
export let DateFormat = (time=null, separator='-') => {
	let date = new Date(time)
	let year = date.getFullYear()
	let month = date.getMonth() < 9 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
	let day = date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()
	let d = year + separator + month + separator + day
	return d
}
