mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Fix period boundaries in Energy dashboard (#25728)
This commit is contained in:
parent
89ce6870f6
commit
8149ee60cb
@ -679,7 +679,9 @@ export const getEnergyDataCollection = (
|
||||
const period =
|
||||
preferredPeriod === "today" && hour === "0" ? "yesterday" : preferredPeriod;
|
||||
|
||||
[collection.start, collection.end] = calcDateRange(hass, period);
|
||||
const [start, end] = calcDateRange(hass, period);
|
||||
collection.start = calcDate(start, startOfDay, hass.locale, hass.config);
|
||||
collection.end = calcDate(end, endOfDay, hass.locale, hass.config);
|
||||
|
||||
const scheduleUpdatePeriod = () => {
|
||||
collection._updatePeriodTimeout = window.setTimeout(
|
||||
|
@ -10,6 +10,8 @@ import {
|
||||
addYears,
|
||||
addMonths,
|
||||
addHours,
|
||||
startOfDay,
|
||||
addDays,
|
||||
} from "date-fns";
|
||||
import type {
|
||||
BarSeriesOption,
|
||||
@ -282,6 +284,10 @@ export function getCompareTransform(start: Date, compareStart?: Date) {
|
||||
) {
|
||||
return (ts: Date) => addMonths(ts, compareMonthDiff);
|
||||
}
|
||||
const compareDayDiff = differenceInDays(start, compareStart);
|
||||
if (compareDayDiff !== 0 && start.getTime() === startOfDay(start).getTime()) {
|
||||
return (ts: Date) => addDays(ts, compareDayDiff);
|
||||
}
|
||||
const compareOffset = start.getTime() - compareStart.getTime();
|
||||
return (ts: Date) => addMilliseconds(ts, compareOffset);
|
||||
}
|
||||
|
@ -297,24 +297,17 @@ export class HuiEnergyPeriodSelector extends SubscribeMixin(LitElement) {
|
||||
}
|
||||
|
||||
private _dateRangeChanged(ev) {
|
||||
const weekStartsOn = firstWeekdayIndex(this.hass.locale);
|
||||
this._startDate = calcDate(
|
||||
ev.detail.value.startDate,
|
||||
startOfDay,
|
||||
this.hass.locale,
|
||||
this.hass.config,
|
||||
{
|
||||
weekStartsOn,
|
||||
}
|
||||
this.hass.config
|
||||
);
|
||||
this._endDate = calcDate(
|
||||
ev.detail.value.endDate,
|
||||
endOfDay,
|
||||
this.hass.locale,
|
||||
this.hass.config,
|
||||
{
|
||||
weekStartsOn,
|
||||
}
|
||||
this.hass.config
|
||||
);
|
||||
|
||||
this._updateCollectionPeriod();
|
||||
|
Loading…
x
Reference in New Issue
Block a user