This is the function called on component loading. The functions return all months with having 31 days. February and months with 30 days are also returned with 31 days. How to limit the number of days 30 in months and February till 28 or 29 on leap year.
const getCalendarCells = (date, items) => {
var cells = [];
try {
if (items === undefined || items === null) {
items = {};
}
/*----- Finding start of the month -----*/
var start = new Date();
start.setMonth(date.getMonth());
start.setFullYear(date.getFullYear());
start.setDate(1);
/*----- Finding start of the calendar date -----*/
while (start.getDay() != 0) {
start.setDate(start.getDate() - 1);
}
/*----- Finding all calendar day of weeks headers -----*/
cells.push(['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']);
/*----- Finding all calendar cells -----*/
var weekCells = [];
for (var i = 0; i <= 42; i++) {
if (i > 0 && i % 7 === 0) {
cells.push(weekCells);
weekCells = [];
}
if (i === 42) {
break;
} else {
var type = (start.getMonth() === date.getMonth() && start.getFullYear() === date.getFullYear()) ? 'THIS' : 'OTHER';
weekCells.push({
data: (type === 'THIS' ? items[start.getDate().toString()] : {}),
value: new Date(start.toString()).getDate(),
type: type
});
start.setDate(start.getDate() + 1);
}
}
console.log(cells)
setReport(cells);
} catch (ex) {}
}