Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time formatting not following browser locale settings in state history chart timeline #196

Closed
sillevl opened this issue Feb 6, 2017 · 16 comments

Comments

@sillevl
Copy link

sillevl commented Feb 6, 2017

As stated in home-assistant/core#184 (comment), the formatting of time is inconsistent in the state history chart timeline. With browser settings set to 'nl', the time is still formated in am/pm format, not in 24h format.

This problem existed also in the logbook (home-assistant/core#184 (comment)) and was fixed in #170. I believe a similar solution could be build for this issue.

The window.hassUtil.formatTime function could be used that was changed in #170 as it takes the locale setting into account when formatting dates and times. (see https://github.com/michaelarnauts/home-assistant-polymer/blob/842c5d5e89960e1bf432b210c84af69ecb424d58/src/util/hass-util.html#L132)

@sillevl sillevl changed the title Timeformatting not following browser locale settings in state history chart timeline Time formatting not following browser locale settings in state history chart timeline Feb 6, 2017
@michaelarnauts
Copy link
Contributor

Can you attach a screenshot of the location where the time is still displayed incorrectly?

@sillevl
Copy link
Author

sillevl commented Feb 6, 2017

schermopname 47

Next to 'Keuken' it says '7:45 a.m. - 5:21 p.m.' This should be '7:45 - 17:21'

@michaelarnauts
Copy link
Contributor

Alright, I see it also now, I didn't hover over the timeline... I'll take a look at it :)

@emlove
Copy link
Contributor

emlove commented Feb 14, 2017

The other portion is the actual timeline labels. They are currently hard-coded to 24 hours, no matter the locale. This is true anywhere we use google charts.

@michaelarnauts
Copy link
Contributor

It seems you need to initialise the google charts with a language. By default this is en. (from: https://developers.google.com/chart/interactive/docs/basic_load_libs#loadwithlocale)

This should do the trick, but I'm unable to test since I'm having issues downloading python dependencies...

diff --git a/src/components/state-history-charts.html b/src/components/state-history-charts.html
index 3755040..d64e57c 100644
--- a/src/components/state-history-charts.html
+++ b/src/components/state-history-charts.html
@@ -85,6 +85,7 @@ Polymer({
   _googleApiLoaded: function () {
     window.google.load('visualization', '1', {
       packages: ['timeline', 'corechart'],
+      language: window.hassUtil.LANGUAGE,
       callback: function () {
         this._apiLoaded = true;
       }.bind(this),

@emlove
Copy link
Contributor

emlove commented Feb 14, 2017

The problem is here: https://github.com/home-assistant/home-assistant-polymer/blob/master/src/components/state-history-chart-line.html#L94 (and equivalent for timeline) where the format is hard-coded.

As I understand, the reason it's hard-coded is that google charts doesn't have an easy way to display a short time string in the locale preferred way.

@michaelarnauts
Copy link
Contributor

@armills indeed, that's the second issue where the times on the h-axis are forced to 24h.

@emlove
Copy link
Contributor

emlove commented Feb 14, 2017

Ah you're right. For some reason I was thinking of the other problem. Adding the language will be good. 👍

@fantaaaaaa
Copy link

is this still on the map? quite confusing for 24h-formatted users as me in europe :)

@kaiomatico
Copy link

Can anyone please test the solution from @michaelarnauts ? I live in Germany and would like to have the logbook in 24h format, just like the rest of the ui properly does change to 24h when setting the correct language.

@andrey-git
Copy link
Contributor

In #847 I'm passing navigator.language

@kaiomatico
Copy link

That's probably also a good alternative to language: window.hassUtil.LANGUAGE, , but does #847 also fix the logbook/history? Sorry if this is a dumb question

@andrey-git
Copy link
Contributor

window.hassUtil.LANGUAGE is not defined.
#847 will fix history.

Logbook is already using navigator.language

@michaelarnauts
Copy link
Contributor

There was a hassUtil.LANGUAGE, that took care of some browser differences since navigator.language didn't work the same on all browsers.

@mcspr
Copy link
Contributor

mcspr commented Feb 27, 2018

Upgrading to 0.64, new Chart.js timeline no longer using 24 hour style as google charts did:
(Using ru-RU locale in the screenshot)
default

At least for tooltip, I noticed that it is using moment.format with locale based output. But there are no locales! Maybe this has something to do with packaging? (include moment-with-locales.js instead of moment.js)
https://github.com/home-assistant/home-assistant-polymer/blob/0ab240c678260e5ec9924407440415e3679f282f/src/components/entity/ha-chart-base.html#L202-L208
default

@c727
Copy link
Contributor

c727 commented Feb 27, 2018

@mcspr please create a new issue for this a we replaced the chart component

@c727 c727 closed this as completed Feb 27, 2018
tkdrob pushed a commit to tkdrob/frontend that referenced this issue Apr 20, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants