-
+
[[formatTime(item.when)]]
@@ -83,6 +81,10 @@ Polymer({
},
},
+ formatTime: function (dateObj) {
+ return window.hassUtil.formatTime(dateObj);
+ },
+
entityClicked: function (ev) {
ev.preventDefault();
this.hass.moreInfoActions.selectEntity(ev.model.item.entityId);
diff --git a/src/components/display-time.html b/src/components/display-time.html
deleted file mode 100644
index 099ba2c9a5..0000000000
--- a/src/components/display-time.html
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
diff --git a/src/components/entity/state-info.html b/src/components/entity/state-info.html
index bdf296b05f..adf15b5af8 100644
--- a/src/components/entity/state-info.html
+++ b/src/components/entity/state-info.html
@@ -1,7 +1,7 @@
-
+
@@ -44,7 +44,7 @@
-
+
diff --git a/src/components/relative-ha-datetime.html b/src/components/ha-relative-time.html
similarity index 91%
rename from src/components/relative-ha-datetime.html
rename to src/components/ha-relative-time.html
index c3edab50d3..b8f487fd4a 100644
--- a/src/components/relative-ha-datetime.html
+++ b/src/components/ha-relative-time.html
@@ -2,7 +2,7 @@
diff --git a/src/home-assistant.html b/src/home-assistant.html
index a98e157a80..3f8267c4e2 100644
--- a/src/home-assistant.html
+++ b/src/home-assistant.html
@@ -1,5 +1,3 @@
-
-
diff --git a/src/more-infos/more-info-sun.html b/src/more-infos/more-info-sun.html
index 5eaaa4105e..ce266df5f5 100644
--- a/src/more-infos/more-info-sun.html
+++ b/src/more-infos/more-info-sun.html
@@ -1,6 +1,6 @@
-
+
@@ -10,7 +10,7 @@
[[itemCaption(item)]]
-
+
[[itemValue(item)]]
diff --git a/src/util/hass-util.html b/src/util/hass-util.html
index cffcb55e9d..81ea1148cd 100644
--- a/src/util/hass-util.html
+++ b/src/util/hass-util.html
@@ -1,3 +1,5 @@
+
+
@@ -68,18 +70,47 @@ window.hassUtil.dynamicContentUpdater = function (root, newElementTag, attribute
}
};
+window.fecha.masks.haDateTime = (window.fecha.masks.shortTime + ' ' +
+ window.fecha.masks.mediumDate);
+
window.hassUtil.formatDateTime = function (dateObj) {
- return window.moment(dateObj).format('lll');
+ return window.fecha.format(dateObj, 'haDateTime');
};
window.hassUtil.formatDate = function (dateObj) {
- return window.moment(dateObj).format('ll');
+ return window.fecha.format(dateObj, 'mediumDate');
};
window.hassUtil.formatTime = function (dateObj) {
- return window.moment(dateObj).format('LT');
+ return window.fecha.format(dateObj, 'shortTime');
};
+window.hassUtil.relativeTime = function (dateObj) {
+ var delta = (new Date() - dateObj) / 1000;
+ var tests = window.hassUtil.relativeTime.tests;
+ var i;
+
+ for (i = 0; i < tests.length; i += 2) {
+ if (delta < tests[i]) {
+ delta = Math.floor(delta);
+ return delta === 1 ? '1 ' + tests[i + 1] : delta + ' ' + tests[i + 1] + 's';
+ }
+
+ delta /= tests[i];
+ }
+
+ delta = Math.floor(delta);
+ return delta === 1 ? '1 week' : delta + ' weeks';
+};
+
+window.hassUtil.relativeTime.tests = [
+ 60, 'second',
+ 60, 'minute',
+ 24, 'hour',
+ 7, 'day',
+];
+
+
window.hassUtil.stateCardType = function (hass, state) {
if (state.state === 'unavailable') {
return 'display';