Bug Fix, can't create schedule on Sunday (#13876)

This commit is contained in:
Ignacio Hernandez-Ros 2022-09-28 11:08:30 +02:00 committed by GitHub
parent 61d09072a7
commit 3959a7475c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -206,6 +206,7 @@ class HaScheduleForm extends LitElement {
private get _events() { private get _events() {
const events: any[] = []; const events: any[] = [];
const currentDay = new Date().getDay(); const currentDay = new Date().getDay();
const baseDay = currentDay === 0 ? 7 : currentDay;
for (const [i, day] of weekdays.entries()) { for (const [i, day] of weekdays.entries()) {
if (!this[`_${day}`].length) { if (!this[`_${day}`].length) {
@ -214,7 +215,7 @@ class HaScheduleForm extends LitElement {
this[`_${day}`].forEach((item: ScheduleDay, index: number) => { this[`_${day}`].forEach((item: ScheduleDay, index: number) => {
// Add 7 to 0 because we start the calendar on Monday // Add 7 to 0 because we start the calendar on Monday
const distance = i - currentDay + (i === 0 ? 7 : 0); const distance = i - baseDay + (i === 0 ? 7 : 0);
const start = new Date(); const start = new Date();
start.setDate(start.getDate() + distance); start.setDate(start.getDate() + distance);