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:
Yevgeniy 2018-06-13 01:29:21 +06:00 committed by c727
parent cf3d864378
commit 8e8d907090

View File

@ -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);