creating a custom calendar with moment using days/weeks and headings
Got it using a table as headers, and converted weeks and days using moment
const startWeek = moment().startOf('month').week();
const endWeek = moment().endOf('month').week();
let calendar = []
for(var week = startWeek; week<endWeek;week++){
calendar.push({
week:week,
days:Array(7).fill(0).map((n, i) => moment().week(week).startOf('week').clone().add(n + i, 'day'))
})
}
Base on all the answers above:
const calendar = [];
const today = moment();
const startDay = today.clone().startOf('month').startOf('week');
const endDay = today.clone().endOf('month').endOf('week');
let date = startDay.clone().subtract(1, 'day');
while (date.isBefore(endDay, 'day'))
calendar.push({
days: Array(7).fill(0).map(() => date.add(1, 'day').clone())
});
Based on the answer provided by caffeinescript I created this calendar that would also work around year boundaries.
const startDay = moment().clone().startOf('month').startOf('week');
const endDay = moment().clone().endOf('month').endOf('week');
var calendar = [];
var index = startDay.clone();
while (index.isBefore(endDay, 'day')) {
calendar.push(
new Array(7).fill(0).map(
function(n, i) {
return {date: index.add(1, 'day').date()};
}
)
);
}