1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-04-02 00:27:49 +01:00

Add day of week to energy chart tooltips (#29803)

* Add day of week to energy chart tooltips

* New localization helpers
This commit is contained in:
gpoitch
2026-02-25 08:31:00 -05:00
committed by GitHub
parent 1cbc38f231
commit 809fa10135
2 changed files with 41 additions and 1 deletions

View File

@@ -210,3 +210,39 @@ const formatDateWeekdayShortMem = memoizeOne(
timeZone: resolveTimeZone(locale.time_zone, serverTimeZone),
})
);
// Mon, Aug 10
export const formatDateWeekdayVeryShortDate = (
dateObj: Date,
locale: FrontendLocaleData,
config: HassConfig
) =>
formatDateWeekdayVeryShortDateMem(locale, config.time_zone).format(dateObj);
const formatDateWeekdayVeryShortDateMem = memoizeOne(
(locale: FrontendLocaleData, serverTimeZone: string) =>
new Intl.DateTimeFormat(locale.language, {
weekday: "short",
month: "short",
day: "numeric",
timeZone: resolveTimeZone(locale.time_zone, serverTimeZone),
})
);
// Mon, Aug 10, 2021
export const formatDateWeekdayShortDate = (
dateObj: Date,
locale: FrontendLocaleData,
config: HassConfig
) => formatDateWeekdayShortDateMem(locale, config.time_zone).format(dateObj);
const formatDateWeekdayShortDateMem = memoizeOne(
(locale: FrontendLocaleData, serverTimeZone: string) =>
new Intl.DateTimeFormat(locale.language, {
weekday: "short",
month: "short",
day: "numeric",
year: "numeric",
timeZone: resolveTimeZone(locale.time_zone, serverTimeZone),
})
);

View File

@@ -28,6 +28,8 @@ import {
formatDateMonthYear,
formatDateShort,
formatDateVeryShort,
formatDateWeekdayShortDate,
formatDateWeekdayVeryShortDate,
} from "../../../../../common/datetime/format_date";
import { formatTime } from "../../../../../common/datetime/format_time";
import type { ECOption } from "../../../../../resources/echarts/echarts";
@@ -222,7 +224,9 @@ function formatTooltip(
if (suggestedPeriod === "month") {
period = `${formatDateMonthYear(date, locale, config)}`;
} else if (suggestedPeriod === "day") {
period = `${(showCompareYear ? formatDateShort : formatDateVeryShort)(date, locale, config)}`;
period = showCompareYear
? formatDateWeekdayShortDate(date, locale, config)
: formatDateWeekdayVeryShortDate(date, locale, config);
} else {
period = `${
compare