From 5cb98eef99509a738b65a1fa0ef7d060bca55ea9 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sun, 3 Sep 2023 12:07:59 +0200 Subject: [PATCH] Honor the time display preference of the user set in HA --- dist/meteofrance-weather-card.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/dist/meteofrance-weather-card.js b/dist/meteofrance-weather-card.js index c36f989..586b7f1 100644 --- a/dist/meteofrance-weather-card.js +++ b/dist/meteofrance-weather-card.js @@ -292,6 +292,7 @@ class MeteofranceWeatherCard extends LitElement { next_rising = new Date(sun.attributes.next_rising); next_setting = new Date(sun.attributes.next_setting); } + const hour12 = this.hass.locale.time_format == "12" ? true : this.hass.locale.time_format == "24" ? false : undefined; this.numberElements++; @@ -345,7 +346,9 @@ class MeteofranceWeatherCard extends LitElement { ${next_rising ? this.renderDetail( - next_rising.toLocaleTimeString(), + next_rising.toLocaleTimeString([], { + hour12: hour12, + }), "Heure de lever", "mdi:weather-sunset-up" ) @@ -353,7 +356,9 @@ class MeteofranceWeatherCard extends LitElement { ${next_setting ? this.renderDetail( - next_setting.toLocaleTimeString(), + next_setting.toLocaleTimeString([], { + hour12: hour12, + }), "Heure de coucher", "mdi:weather-sunset-down" ) @@ -457,6 +462,7 @@ class MeteofranceWeatherCard extends LitElement { const lang = this.hass.selectedLanguage || this.hass.language; const isDaily = this.isDailyForecast(forecast); + const hour12 = this.hass.locale.time_format == "12" ? true : this.hass.locale.time_format == "24" ? false : undefined; this.numberElements++; return html` `; } - renderDailyForecast(daily, lang, isDaily) { + renderDailyForecast(daily, lang, isDaily, hour12) { return html`