Ad

Change Start Of The Week To Monday

- 1 answer

I am trying to follow this tutorial.

It builds a calendar where Sunday is the first day of the week. I don't completely grok how it works, honestly. What I cannot understand is how to make it show a calendar where week starts from Monday, not Sunday. I think the problem is somewhere in this line:

date = this.state.month.clone().startOf("month").add("w" - 1).day(0),

I tried day(1), then it builds weeks starting from Monday, but if the 1st day of the month is Sunday, then it leaves this day on the screen of the previous month, showing the current one starting from the 2nd day:

previous monththis month

How can I do this?

Ad

Answer

OK, I got it. Instead of trying to get explicit day as start of the week, startOf('isoWeek') should be used. So instead of

date = this.state.month.clone().startOf("month").add("w" - 1).day(0),

I did:

date = this.state.month.clone().startOf("month").add("w"-1).startOf('isoWeek'),

and now it looks right:

enter image description here

Ad
source: stackoverflow.com
Ad