Fix weather more info date display (#17440)

This commit is contained in:
Bram Kragten 2023-07-31 17:54:39 +02:00 committed by GitHub
parent f953ec6e1c
commit 4612099e88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 25 deletions

View File

@ -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 {
></ha-svg-icon>
`
: ""}
${hourly
? html`
<div class="main">
${formatTimeWeekday(
new Date(item.datetime),
this.hass.locale,
this.hass.config
)}
</div>
`
: html`
<div class="main">
<div class="main">
${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")}
</div>
`}
: 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
)}
`}
</div>
<div class="templow">
${this._showValue(item.templow)
? `${formatNumber(item.templow!, this.hass.locale)}

View File

@ -352,9 +352,10 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
<div>
${dayNight
? html`
${new Date(item.datetime).toLocaleDateString(
this.hass!.language,
{ weekday: "short" }
${formatDateWeekdayShort(
new Date(item.datetime),
this.hass!.locale,
this.hass!.config
)}
<div class="daynight">
${item.is_daytime !== false