From 5357fc25d8c2486db36b91ebaa2c29659f00c394 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Wed, 26 Apr 2017 04:56:23 +0200 Subject: [PATCH] Rewrite _currentDate to work in all time zones (#266) * Rewrite _currentDate to work in all time zones The method toISOString() returns a timestamp in UTC. Thus, midnight in the CET timezone (UTC+1) was converted into yesterday@2300 and then that date was used as the current date. This made the logbook and history start with yesterday's data, at least for locations east of UTC. The new version avoids this by using methods that work in local time. * Remove an embarrassing amount of lint * Rewrite to be more concise Proposed by @armills. --- panels/history/ha-panel-history.html | 4 ++-- panels/logbook/ha-panel-logbook.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/panels/history/ha-panel-history.html b/panels/history/ha-panel-history.html index f84209369a..060633817c 100644 --- a/panels/history/ha-panel-history.html +++ b/panels/history/ha-panel-history.html @@ -121,8 +121,8 @@ Polymer({ type: String, value: function () { var value = new Date(); - value.setHours(0, 0, 0); - return value.toISOString().split('T')[0]; + var today = new Date(Date.UTC(value.getFullYear(), value.getMonth(), value.getDate())); + return today.toISOString().split('T')[0]; }, }, diff --git a/panels/logbook/ha-panel-logbook.html b/panels/logbook/ha-panel-logbook.html index 85fbcec5e0..bea02149b9 100644 --- a/panels/logbook/ha-panel-logbook.html +++ b/panels/logbook/ha-panel-logbook.html @@ -98,8 +98,8 @@ Polymer({ type: String, value: function () { var value = new Date(); - value.setHours(0, 0, 0); - return value.toISOString().split('T')[0]; + var today = new Date(Date.UTC(value.getFullYear(), value.getMonth(), value.getDate())); + return today.toISOString().split('T')[0]; }, },