mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
Change weather card to support forecasts with two modes (#1277)
* Separation of date and time * Remove <div>, hour to numeric, text uppercase * Revert style, fix <br>
This commit is contained in:
parent
cf3d864378
commit
8e8d907090
@ -128,7 +128,11 @@ class HaWeatherCard extends
|
||||
<div class="forecast">
|
||||
<template is="dom-repeat" items="[[forecast]]">
|
||||
<div>
|
||||
<div class="weekday">[[computeDateTime(item.datetime)]]</div>
|
||||
<div class="weekday">[[computeDate(item.datetime)]]<br>
|
||||
<template is="dom-if" if="[[!item.templow]]">
|
||||
[[computeTime(item.datetime)]]
|
||||
</template>
|
||||
</div>
|
||||
<template is="dom-if" if="[[item.condition]]">
|
||||
<div class="icon">
|
||||
<iron-icon icon="[[getWeatherIcon(item.condition)]]"></iron-icon>
|
||||
@ -237,16 +241,20 @@ class HaWeatherCard extends
|
||||
return typeof item !== 'undefined' && item !== null;
|
||||
}
|
||||
|
||||
computeDateTime(data) {
|
||||
computeDate(data) {
|
||||
const date = new Date(data);
|
||||
return date.toLocaleDateString(
|
||||
this.hass.selectedLanguage || this.hass.language,
|
||||
{ weekday: 'short' }
|
||||
);
|
||||
}
|
||||
|
||||
computeTime(data) {
|
||||
const date = new Date(data);
|
||||
const provider = this.stateObj.attributes.attribution;
|
||||
if (provider === 'Powered by Dark Sky' || provider === 'Data provided by OpenWeatherMap') {
|
||||
return date.toLocaleTimeString(
|
||||
this.hass.selectedLanguage || this.hass.language,
|
||||
{ hour: 'numeric' }
|
||||
);
|
||||
}
|
||||
return date.toLocaleDateString(this.hass.selectedLanguage || this.hass.language, { weekday: 'short' });
|
||||
}
|
||||
}
|
||||
customElements.define('ha-weather-card', HaWeatherCard);
|
||||
|
Loading…
x
Reference in New Issue
Block a user