export const DAYS = [{
		nums: 31
	},
	{
		nums: 28
	},
	{
		nums: 31
	},
	{
		nums: 30
	},
	{
		nums: 31
	},
	{
		nums: 30
	},
	{
		nums: 31
	},
	{
		nums: 31
	},
	{
		nums: 30
	},
	{
		nums: 31
	},
	{
		nums: 30
	},
	{
		nums: 31
	},
];

/**
 * @param {Number} year e:2014
 * @param {Number} month 8 
 * @param {Boolean} bol true时，返回42天全日期  
 * */
export const getDays = function(year, month, bol) {
	let index = month - 1,
		days = [],
		length = DAYS[index].nums,
		day = new Date(`${year}/${month}/01`).getDay(),
		last_month_length = index == 0 ? DAYS[11].nums : DAYS[index - 1].nums,
		last_month = index == 0 ? 12 : month - 1,
		last_year = index == 0 ? year - 1 : year,
		next_month = month == 12 ? 1 : month + 1,
		next_year = next_month == 1 ? year + 1 : year;
	
	if((last_year % 4 === 0) && (last_year % 100 !== 0 || last_year % 400 === 0) && index == 2){
		last_month_length++
	}
	
	for (let i = 0; i < day; i++) {
		let d = last_month_length - day + i;
		days.push({
			day: bol ? d : '',
			active: false,
			date: `${last_year}-${proNum(last_month)}-${proNum(d)}`
		})
	}
	if ((year % 4 === 0) && (year % 100 !== 0 || year % 400 === 0) && index == 1) { //闰年二月份天数
		length++
	}
	
	function proNum(m) {
		return m < 10 ? '0' + m : m;
	}
	for (let i = 1; i <= length; i++) {
		days.push({
			day: i,
			active: false,
			date: `${year}-${proNum(month)}-${proNum(i)}`
		})
	};
	if (days.length < 42) {
		let length = 42 - days.length
		for (let i = 1; i <= length; i++) {
			days.push({
				day: bol ? i : '',
				active: false,
				date: `${next_year}-${proNum(next_month)}-${proNum(i)}`
			})
		}
	}
	return days
}