From a051f29aab38d08b029f075cdcbfa6e724e0d292 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 18 Dec 2021 22:01:30 +0100 Subject: [PATCH] change: mark weekend and fist last monthday --- stripcalender.mjs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/stripcalender.mjs b/stripcalender.mjs index 6ad0ede..882678d 100644 --- a/stripcalender.mjs +++ b/stripcalender.mjs @@ -69,12 +69,10 @@ export class StripCalender 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); @@ -105,12 +103,27 @@ export class StripCalender 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"); + } } -- 2.39.5