Make frontend UTC aware

This commit is contained in:
Paulus Schoutsen 2015-04-28 22:34:44 -07:00
parent e0ecb64a10
commit 54904a1630
8 changed files with 45 additions and 28 deletions

View File

@ -1,2 +1,2 @@
""" DO NOT MODIFY. Auto-generated by build_frontend script """ """ DO NOT MODIFY. Auto-generated by build_frontend script """
VERSION = "93774c7a1643c7e3f9cbbb1554b36683" VERSION = "37514744ac03f1d764a70b8e6a7e572f"

File diff suppressed because one or more lines are too long

View File

@ -8,16 +8,17 @@
</template> </template>
<script> <script>
(function() { (function() {
var timeFormatOptions = {hour: 'numeric', minute: '2-digit'}; var uiUtil = window.hass.uiUtil;
Polymer({ Polymer({
time: "", time: "",
dateObjChanged: function(oldVal, newVal) { dateObjChanged: function(oldVal, newVal) {
if (!newVal) { if (newVal) {
this.time = uiUtil.formatTime(newVal);
} else {
this.time = ""; this.time = "";
} }
this.time = newVal.toLocaleTimeString([], timeFormatOptions);
}, },
}); });
})(); })();

View File

@ -2,7 +2,7 @@
<link rel="import" href="../resources/moment-js.html"> <link rel="import" href="../resources/moment-js.html">
<polymer-element name="relative-ha-datetime" attributes="datetime"> <polymer-element name="relative-ha-datetime" attributes="datetime datetimeObj">
<template> <template>
{{ relativeTime }} {{ relativeTime }}
</template> </template>
@ -34,8 +34,15 @@
this.updateRelative(); this.updateRelative();
}, },
datetimeObjChanged: function(oldVal, newVal) {
this.parsedDateTime = newVal;
this.updateRelative();
},
updateRelative: function() { updateRelative: function() {
this.relativeTime = this.parsedDateTime ? moment(this.parsedDateTime).fromNow() : ""; this.relativeTime = this.parsedDateTime ?
moment(this.parsedDateTime).fromNow() : "";
}, },
}); });
})(); })();

View File

@ -37,8 +37,8 @@
</div> </div>
<div class="time-ago"> <div class="time-ago">
<core-tooltip label="{{stateObj.lastChanged}}" position="bottom"> <core-tooltip label="{{stateObj.lastChangedAsDate | formatDateTime}}" position="bottom">
<relative-ha-datetime datetime="{{stateObj.lastChanged}}"></relative-ha-datetime> <relative-ha-datetime datetimeObj="{{stateObj.lastChangedAsDate}}"></relative-ha-datetime>
</core-tooltip> </core-tooltip>
</div> </div>

@ -1 +1 @@
Subproject commit 56f896efa573aaa9554812a3c41b78278bce2064 Subproject commit 124b5df8ffb08bd7db22912865dba80845815e5d

View File

@ -7,18 +7,6 @@
'light', 'group', 'sun', 'configurator', 'thermostat', 'script' 'light', 'group', 'sun', 'configurator', 'thermostat', 'script'
]; ];
// Register some polymer filters
PolymerExpressions.prototype.HATimeToDate = function(timeString) {
if (!timeString) return;
return window.hass.util.parseDateTime(timeString);
};
PolymerExpressions.prototype.HATimeStripDate = function(timeString) {
return (timeString || "").split(' ')[0];
};
// Add some frontend specific helpers to the models // Add some frontend specific helpers to the models
Object.defineProperties(window.hass.stateModel.prototype, { Object.defineProperties(window.hass.stateModel.prototype, {
// how to render the card for this state // how to render the card for this state
@ -81,3 +69,5 @@
window.hass.uiUtil = {}; window.hass.uiUtil = {};
})(); })();
</script> </script>
<link rel="import" href="./moment-js.html">

View File

@ -3,3 +3,22 @@
--> -->
<script src="../bower_components/moment/moment.js"></script> <script src="../bower_components/moment/moment.js"></script>
<script>
window.hass.uiUtil.formatTime = function(dateObj) {
return moment(dateObj).format('LT');
};
window.hass.uiUtil.formatDateTime = function(dateObj) {
return moment(dateObj).format('lll');
};
window.hass.uiUtil.formatDate = function(dateObj) {
return moment(dateObj).format('ll');
};
PolymerExpressions.prototype.formatTime = window.hass.uiUtil.formatTime;
PolymerExpressions.prototype.formatDateTime = window.hass.uiUtil.formatDateTime;
PolymerExpressions.prototype.formatDate = window.hass.uiUtil.formatDate;
</script>