Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- calendarMatrix() {
- function range(start, end) {
- let ret = [];
- for (let i = start; i < end; i++) {
- ret.push(i);
- }
- return ret;
- }
- function nulls(count) {
- return (new Array(count)).fill(null);
- }
- function actualWeekday(day) {
- return (day + 6) % 7;
- }
- const startDay = new Date(this.year, this.month, 1);
- const endDay = new Date(this.year, this.month + 1, 0);
- const calendarPool = [
- ...nulls(actualWeekday(startDay.getDay())),
- ...range(startDay.getDate(), endDay.getDate() + 1),
- ...nulls(6 - actualWeekday(endDay.getDay())),
- ];
- console.log(calendarPool);
- let calendarMatrix = [];
- for (let step = 0; step < Math.floor(calendarPool.length / 7); step++) {
- calendarMatrix.push(calendarPool.slice(step * 7, (step + 1) * 7))
- }
- return calendarMatrix;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement