let th = null;
for (let i = 1; i <= days; i++) {
- this._date.setDate(i);
th = document.createElement("th");
- if (this._date.getDay() == 0
- || this._date.getDay() == 6)
- th.classList.add("weekend");
+ this.markFirstAndLastDayOfMonth(th, i, days);
+ this.markWeekendDays(th, i);
th.innerText = i;
tr.appendChild(th);
this._date.setDate(i);
th = document.createElement("th");
- if (this._date.getDay() == 0
- || this._date.getDay() == 6)
- th.classList.add("weekend");
+ this.markFirstAndLastDayOfMonth(th, i, days);
+ this.markWeekendDays(th, i);
th.innerText = weekday[this._date.getDay()];
tr.appendChild(th);
}
}
+
+ markFirstAndLastDayOfMonth(th, day, maxdays)
+ {
+ if (day == 1)
+ th.classList.add("first");
+ if (day == maxdays)
+ th.classList.add("last");
+ }
+
+ markWeekendDays(th, day)
+ {
+ this._date.setDate(day);
+
+ if (this._date.getDay() == 0 || this._date.getDay() == 6)
+ th.classList.add("weekend");
+ }
}