Fix first day of the week locale issue with scheduler (#14529)

fixes undefined
This commit is contained in:
Philip Allgaier 2022-12-05 14:54:38 +01:00 committed by GitHub
parent ef3caf91f1
commit 07ad429f8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -208,7 +208,10 @@ class HaScheduleForm extends LitElement {
private get _events() {
const events: any[] = [];
const currentDay = new Date().getDay();
const baseDay = currentDay === 0 ? 7 : currentDay;
const baseDay =
currentDay === 0 && firstWeekdayIndex(this.hass.locale) === 1
? 7
: currentDay;
for (const [i, day] of weekdays.entries()) {
if (!this[`_${day}`].length) {
@ -216,8 +219,11 @@ class HaScheduleForm extends LitElement {
}
this[`_${day}`].forEach((item: ScheduleDay, index: number) => {
// Add 7 to 0 because we start the calendar on Monday
const distance = i - baseDay + (i === 0 ? 7 : 0);
// Add 7 to 0 because we start the calendar on Monday, except when the locale says otherwise (firstWeekdayIndex() != 1)
const distance =
i -
baseDay +
(i === 0 && firstWeekdayIndex(this.hass.locale) === 1 ? 7 : 0);
const start = new Date();
start.setDate(start.getDate() + distance);