From 1d13126bb5ad9207c9ed952b8ba6ceba92134a67 Mon Sep 17 00:00:00 2001 From: Nigel Rook Date: Tue, 2 Jan 2018 13:02:26 +0000 Subject: [PATCH] Use current date for input_datetime time rendering (#754) * Use current date for input_datetime time rendering Chrome has a bug where it fails to render times correctly using toLocaleTimeString for certain dates in the past with non-normal daylight saving rules. For the UK and New Zealand, this includes 1970-01-01. Instead of using this as the date when rendering the time for a time only input_datetime, use the current date. * Add comment * Lint --- js/common/util/compute_state_display.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/common/util/compute_state_display.js b/js/common/util/compute_state_display.js index 4acb9390ea..5894146d88 100644 --- a/js/common/util/compute_state_display.js +++ b/js/common/util/compute_state_display.js @@ -27,8 +27,11 @@ export default function computeStateDisplay(localize, stateObj, language) { ); stateObj._stateDisplay = formatDate(date, language); } else if (!stateObj.attributes.has_date) { + const now = new Date(); date = new Date( - 1970, 0, 1, + // Due to bugs.chromium.org/p/chromium/issues/detail?id=797548 + // don't use artificial 1970 year. + now.getFullYear(), now.getMonth(), now.getDay(), stateObj.attributes.hour, stateObj.attributes.minute );