mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix week start on Saturday for scheduler (#14566)
This commit is contained in:
parent
b06db26540
commit
34dfaa5a0f
@ -6,7 +6,7 @@ import interactionPlugin from "@fullcalendar/interaction";
|
|||||||
import timeGridPlugin from "@fullcalendar/timegrid";
|
import timeGridPlugin from "@fullcalendar/timegrid";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import timegridStyle from "@fullcalendar/timegrid/main.css";
|
import timegridStyle from "@fullcalendar/timegrid/main.css";
|
||||||
import { isSameDay } from "date-fns";
|
import { addDays, isSameDay, isSameWeek, nextDay } from "date-fns";
|
||||||
import {
|
import {
|
||||||
css,
|
css,
|
||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
@ -245,11 +245,6 @@ class HaScheduleForm extends LitElement {
|
|||||||
|
|
||||||
private get _events() {
|
private get _events() {
|
||||||
const events: any[] = [];
|
const events: any[] = [];
|
||||||
const currentDay = new Date().getDay();
|
|
||||||
const baseDay =
|
|
||||||
currentDay === 0 && firstWeekdayIndex(this.hass.locale) === 1
|
|
||||||
? 7
|
|
||||||
: currentDay;
|
|
||||||
|
|
||||||
for (const [i, day] of weekdays.entries()) {
|
for (const [i, day] of weekdays.entries()) {
|
||||||
if (!this[`_${day}`].length) {
|
if (!this[`_${day}`].length) {
|
||||||
@ -257,14 +252,15 @@ 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, except when the locale says otherwise (firstWeekdayIndex() != 1)
|
let date = nextDay(new Date(), i as Day);
|
||||||
const distance =
|
if (
|
||||||
i -
|
!isSameWeek(date, new Date(), {
|
||||||
baseDay +
|
weekStartsOn: firstWeekdayIndex(this.hass.locale),
|
||||||
(i === 0 && firstWeekdayIndex(this.hass.locale) === 1 ? 7 : 0);
|
})
|
||||||
|
) {
|
||||||
const start = new Date();
|
date = addDays(date, -7);
|
||||||
start.setDate(start.getDate() + distance);
|
}
|
||||||
|
const start = new Date(date);
|
||||||
const start_tokens = item.from.split(":");
|
const start_tokens = item.from.split(":");
|
||||||
start.setHours(
|
start.setHours(
|
||||||
parseInt(start_tokens[0]),
|
parseInt(start_tokens[0]),
|
||||||
@ -273,8 +269,7 @@ class HaScheduleForm extends LitElement {
|
|||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
const end = new Date();
|
const end = new Date(date);
|
||||||
end.setDate(end.getDate() + distance);
|
|
||||||
const end_tokens = item.to.split(":");
|
const end_tokens = item.to.split(":");
|
||||||
end.setHours(parseInt(end_tokens[0]), parseInt(end_tokens[1]), 0, 0);
|
end.setHours(parseInt(end_tokens[0]), parseInt(end_tokens[1]), 0, 0);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user