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, mdiWeatherWindy,
} from "@mdi/js"; } from "@mdi/js";
import { import {
css,
CSSResultGroup, CSSResultGroup,
html,
LitElement, LitElement,
PropertyValues, PropertyValues,
css,
html,
nothing, nothing,
} from "lit"; } from "lit";
import { customElement, property, state } from "lit/decorators"; 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 { formatNumber } from "../../../common/number/format_number";
import "../../../components/ha-svg-icon"; import "../../../components/ha-svg-icon";
import { import {
ForecastEvent,
WeatherEntity,
getDefaultForecastType, getDefaultForecastType,
getForecast, getForecast,
getWeatherUnit, getWeatherUnit,
getWind, getWind,
subscribeForecast, subscribeForecast,
ForecastEvent,
WeatherEntity,
weatherIcons, weatherIcons,
} from "../../../data/weather"; } from "../../../data/weather";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
@ -122,6 +122,7 @@ class MoreInfoWeather extends LitElement {
); );
const forecast = forecastData?.forecast; const forecast = forecastData?.forecast;
const hourly = forecastData?.type === "hourly"; const hourly = forecastData?.type === "hourly";
const dayNight = forecastData?.type === "twice_daily";
return html` return html`
${this._showValue(this.stateObj.attributes.temperature) ${this._showValue(this.stateObj.attributes.temperature)
@ -225,28 +226,34 @@ class MoreInfoWeather extends LitElement {
></ha-svg-icon> ></ha-svg-icon>
` `
: ""} : ""}
${hourly <div class="main">
? html` ${dayNight
<div class="main"> ? html`
${formatTimeWeekday(
new Date(item.datetime),
this.hass.locale,
this.hass.config
)}
</div>
`
: html`
<div class="main">
${formatDateWeekdayDay( ${formatDateWeekdayDay(
new Date(item.datetime), new Date(item.datetime),
this.hass.locale, this.hass!.locale,
this.hass.config this.hass!.config
)} )}
${item.is_daytime !== false (${item.is_daytime !== false
? this.hass!.localize("ui.card.weather.day") ? this.hass!.localize("ui.card.weather.day")
: this.hass!.localize("ui.card.weather.night")} : this.hass!.localize("ui.card.weather.night")})
</div> `
`} : 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"> <div class="templow">
${this._showValue(item.templow) ${this._showValue(item.templow)
? `${formatNumber(item.templow!, this.hass.locale)} ? `${formatNumber(item.templow!, this.hass.locale)}

View File

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