-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Round values for relative time instead of flooring #6225
Conversation
755c200
to
c1acb20
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Thanks !
Actually, we can't merge this unless there is also a PR to make sure the Python side is up to date: https://github.com/home-assistant/core/blob/dev/homeassistant/util/dt.py#L180 This version still uses rounding down. |
c1acb20
to
1940c8a
Compare
Makes sense, I'll look into it. Meanwhile I've updated this PR to get rid of the |
@balloob I've also created a PR for core: home-assistant/core#37125 |
af0a169
to
d73f1c3
Compare
d73f1c3
to
e06b23f
Compare
I have reviewed the HA core PR (looks good) But it doesn’t (and didn’t previously) output ‘weeks’ that were mentioned in the description above. It must be that 13days=1week was coming from somewhere else as I think it would now output: 13days=>13 days |
@davet2001 The old code did send out "week" / "weeks", as can be seen here: https://github.com/home-assistant/frontend/pull/6225/files#diff-94c31734a9546e7f680a38e3608c24eeL43 I've kept this behavior intact for the frontend: https://github.com/home-assistant/frontend/pull/6225/files#diff-94c31734a9546e7f680a38e3608c24eeR24 This means that the new situation, just like the old one, means that frontend and core have different "fallback" time units of years and weeks, respectively. |
Proposed change
Currently, the value used for displaying a relative time is floored before it's interpolated into the localized string. Many times, this has led me to misinterpret the actual value:
This change modifies the
relativeTime
function to useMath.round
instead ofMath.floor
so the output more closely matches the actual relative time of the input.Type of change
Example configuration
Just put any entity with
device_class: timestamp
on a Lovelace dashboard and fake the state to try out different edge cases. Unfortunately, I could not get a simple template withrelative_time
to work.Checklist
If user exposed functionality or configuration variables are added/changed: