From 4612099e88089edc347ef9de8cb87b4d5c843beb Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Mon, 31 Jul 2023 17:54:39 +0200 Subject: [PATCH] Fix weather more info date display (#17440) --- .../more-info/controls/more-info-weather.ts | 51 +++++++++++-------- .../cards/hui-weather-forecast-card.ts | 7 +-- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/dialogs/more-info/controls/more-info-weather.ts b/src/dialogs/more-info/controls/more-info-weather.ts index f76e2517f1..ddc68e7b96 100644 --- a/src/dialogs/more-info/controls/more-info-weather.ts +++ b/src/dialogs/more-info/controls/more-info-weather.ts @@ -6,11 +6,11 @@ import { mdiWeatherWindy, } from "@mdi/js"; import { - css, CSSResultGroup, - html, LitElement, PropertyValues, + css, + html, nothing, } from "lit"; import { customElement, property, state } from "lit/decorators"; @@ -19,13 +19,13 @@ import { formatTimeWeekday } from "../../../common/datetime/format_time"; import { formatNumber } from "../../../common/number/format_number"; import "../../../components/ha-svg-icon"; import { + ForecastEvent, + WeatherEntity, getDefaultForecastType, getForecast, getWeatherUnit, getWind, subscribeForecast, - ForecastEvent, - WeatherEntity, weatherIcons, } from "../../../data/weather"; import { HomeAssistant } from "../../../types"; @@ -122,6 +122,7 @@ class MoreInfoWeather extends LitElement { ); const forecast = forecastData?.forecast; const hourly = forecastData?.type === "hourly"; + const dayNight = forecastData?.type === "twice_daily"; return html` ${this._showValue(this.stateObj.attributes.temperature) @@ -225,28 +226,34 @@ class MoreInfoWeather extends LitElement { > ` : ""} - ${hourly - ? html` -
- ${formatTimeWeekday( - new Date(item.datetime), - this.hass.locale, - this.hass.config - )} -
- ` - : html` -
+
+ ${dayNight + ? html` ${formatDateWeekdayDay( new Date(item.datetime), - this.hass.locale, - this.hass.config + this.hass!.locale, + this.hass!.config )} - ${item.is_daytime !== false + (${item.is_daytime !== false ? this.hass!.localize("ui.card.weather.day") - : this.hass!.localize("ui.card.weather.night")} -
- `} + : this.hass!.localize("ui.card.weather.night")}) + ` + : hourly + ? html` + ${formatTimeWeekday( + new Date(item.datetime), + this.hass!.locale, + this.hass!.config + )} + ` + : html` + ${formatDateWeekdayDay( + new Date(item.datetime), + this.hass!.locale, + this.hass!.config + )} + `} +
${this._showValue(item.templow) ? `${formatNumber(item.templow!, this.hass.locale)} diff --git a/src/panels/lovelace/cards/hui-weather-forecast-card.ts b/src/panels/lovelace/cards/hui-weather-forecast-card.ts index b5ee99fc86..a1528588bb 100644 --- a/src/panels/lovelace/cards/hui-weather-forecast-card.ts +++ b/src/panels/lovelace/cards/hui-weather-forecast-card.ts @@ -352,9 +352,10 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
${dayNight ? html` - ${new Date(item.datetime).toLocaleDateString( - this.hass!.language, - { weekday: "short" } + ${formatDateWeekdayShort( + new Date(item.datetime), + this.hass!.locale, + this.hass!.config )}
${item.is_daytime !== false