mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-30 20:56:36 +00:00
Use first weekday is history. energy, logbook panels
This commit is contained in:
parent
16848d03ae
commit
fa49fa03da
@ -11,16 +11,25 @@ export const weekdays = [
|
|||||||
"saturday",
|
"saturday",
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
export const firstWeekdayIndex = (locale: FrontendLocaleData): number => {
|
export const firstWeekdayIndex = (
|
||||||
|
locale: FrontendLocaleData
|
||||||
|
): 0 | 1 | 2 | 3 | 4 | 5 | 6 => {
|
||||||
if (locale.first_weekday === FirstWeekday.language) {
|
if (locale.first_weekday === FirstWeekday.language) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if ("weekInfo" in Intl.Locale.prototype) {
|
if ("weekInfo" in Intl.Locale.prototype) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return new Intl.Locale(locale.language).weekInfo.firstDay % 7;
|
return new Intl.Locale(locale.language).weekInfo.firstDay % 7;
|
||||||
}
|
}
|
||||||
return getWeekStartByLocale(locale.language) % 7;
|
return (getWeekStartByLocale(locale.language) % 7) as
|
||||||
|
| 0
|
||||||
|
| 1
|
||||||
|
| 2
|
||||||
|
| 3
|
||||||
|
| 4
|
||||||
|
| 5
|
||||||
|
| 6;
|
||||||
}
|
}
|
||||||
return weekdays.indexOf(locale.first_weekday);
|
return weekdays.indexOf(locale.first_weekday) as 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const firstWeekday = (locale: FrontendLocaleData) => {
|
export const firstWeekday = (locale: FrontendLocaleData) => {
|
||||||
|
@ -16,6 +16,7 @@ import {
|
|||||||
} from "home-assistant-js-websocket/dist/types";
|
} from "home-assistant-js-websocket/dist/types";
|
||||||
import { css, html, LitElement, PropertyValues } from "lit";
|
import { css, html, LitElement, PropertyValues } from "lit";
|
||||||
import { property, state } from "lit/decorators";
|
import { property, state } from "lit/decorators";
|
||||||
|
import { firstWeekdayIndex } from "../../common/datetime/first_weekday";
|
||||||
import { LocalStorage } from "../../common/decorators/local-storage";
|
import { LocalStorage } from "../../common/decorators/local-storage";
|
||||||
import { ensureArray } from "../../common/ensure-array";
|
import { ensureArray } from "../../common/ensure-array";
|
||||||
import { navigate } from "../../common/navigate";
|
import { navigate } from "../../common/navigate";
|
||||||
@ -179,8 +180,9 @@ class HaPanelHistory extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const weekStart = startOfWeek(today);
|
const weekStartsOn = firstWeekdayIndex(this.hass.locale);
|
||||||
const weekEnd = endOfWeek(today);
|
const weekStart = startOfWeek(today, { weekStartsOn });
|
||||||
|
const weekEnd = endOfWeek(today, { weekStartsOn });
|
||||||
|
|
||||||
this._ranges = {
|
this._ranges = {
|
||||||
[this.hass.localize("ui.components.date-range-picker.ranges.today")]: [
|
[this.hass.localize("ui.components.date-range-picker.ranges.today")]: [
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
} from "date-fns/esm";
|
} from "date-fns/esm";
|
||||||
import { css, html, LitElement, PropertyValues } from "lit";
|
import { css, html, LitElement, PropertyValues } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { firstWeekdayIndex } from "../../common/datetime/first_weekday";
|
||||||
import { navigate } from "../../common/navigate";
|
import { navigate } from "../../common/navigate";
|
||||||
import {
|
import {
|
||||||
createSearchParam,
|
createSearchParam,
|
||||||
@ -108,8 +109,9 @@ export class HaPanelLogbook extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const weekStart = startOfWeek(today);
|
const weekStartsOn = firstWeekdayIndex(this.hass.locale);
|
||||||
const weekEnd = endOfWeek(today);
|
const weekStart = startOfWeek(today, { weekStartsOn });
|
||||||
|
const weekEnd = endOfWeek(today, { weekStartsOn });
|
||||||
|
|
||||||
this._ranges = {
|
this._ranges = {
|
||||||
[this.hass.localize("ui.components.date-range-picker.ranges.today")]: [
|
[this.hass.localize("ui.components.date-range-picker.ranges.today")]: [
|
||||||
|
@ -36,6 +36,7 @@ import { EnergyData, getEnergyDataCollection } from "../../../data/energy";
|
|||||||
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
||||||
import { HomeAssistant, ToggleButton } from "../../../types";
|
import { HomeAssistant, ToggleButton } from "../../../types";
|
||||||
import { computeRTLDirection } from "../../../common/util/compute_rtl";
|
import { computeRTLDirection } from "../../../common/util/compute_rtl";
|
||||||
|
import { firstWeekdayIndex } from "../../../common/datetime/first_weekday";
|
||||||
|
|
||||||
@customElement("hui-energy-period-selector")
|
@customElement("hui-energy-period-selector")
|
||||||
export class HuiEnergyPeriodSelector extends SubscribeMixin(LitElement) {
|
export class HuiEnergyPeriodSelector extends SubscribeMixin(LitElement) {
|
||||||
@ -183,7 +184,9 @@ export class HuiEnergyPeriodSelector extends SubscribeMixin(LitElement) {
|
|||||||
this._period === "day"
|
this._period === "day"
|
||||||
? startOfDay(start)
|
? startOfDay(start)
|
||||||
: this._period === "week"
|
: this._period === "week"
|
||||||
? startOfWeek(start, { weekStartsOn: 1 })
|
? startOfWeek(start, {
|
||||||
|
weekStartsOn: firstWeekdayIndex(this.hass.locale),
|
||||||
|
})
|
||||||
: this._period === "month"
|
: this._period === "month"
|
||||||
? startOfMonth(start)
|
? startOfMonth(start)
|
||||||
: startOfYear(start)
|
: startOfYear(start)
|
||||||
@ -195,7 +198,9 @@ export class HuiEnergyPeriodSelector extends SubscribeMixin(LitElement) {
|
|||||||
this._period === "day"
|
this._period === "day"
|
||||||
? startOfToday()
|
? startOfToday()
|
||||||
: this._period === "week"
|
: this._period === "week"
|
||||||
? startOfWeek(new Date(), { weekStartsOn: 1 })
|
? startOfWeek(new Date(), {
|
||||||
|
weekStartsOn: firstWeekdayIndex(this.hass.locale),
|
||||||
|
})
|
||||||
: this._period === "month"
|
: this._period === "month"
|
||||||
? startOfMonth(new Date())
|
? startOfMonth(new Date())
|
||||||
: startOfYear(new Date())
|
: startOfYear(new Date())
|
||||||
@ -231,7 +236,9 @@ export class HuiEnergyPeriodSelector extends SubscribeMixin(LitElement) {
|
|||||||
this._period === "day"
|
this._period === "day"
|
||||||
? endOfDay(startDate)
|
? endOfDay(startDate)
|
||||||
: this._period === "week"
|
: this._period === "week"
|
||||||
? endOfWeek(startDate, { weekStartsOn: 1 })
|
? endOfWeek(startDate, {
|
||||||
|
weekStartsOn: firstWeekdayIndex(this.hass.locale),
|
||||||
|
})
|
||||||
: this._period === "month"
|
: this._period === "month"
|
||||||
? endOfMonth(startDate)
|
? endOfMonth(startDate)
|
||||||
: endOfYear(startDate);
|
: endOfYear(startDate);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user