-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Allow customization of time format #22339
base: dev
Are you sure you want to change the base?
Allow customization of time format #22339
Conversation
This can be just in YAML and described in the documentation. |
I agree with @karwosts. We can simply use the |
I can take care of it. I have most of the changes ready in a separate branch. Didn't want to push them here early, in the event that wasn't the route you wanted to take. |
400ee51
to
97070e7
Compare
if (content === "state") { | ||
if ( | ||
content === "state" || | ||
(this.format && TIMESTAMP_RENDERING_FORMATS.includes(this.format)) |
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.
I don't think we can do this, as relative time is also used for things like last_triggered
, etc.
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.
Yeah, it was something I threw in somewhat last minute when I saw the alternative state_content
timestamps weren't respecting the format. Would adding more specific guards for the other state content types be an acceptable alternative?
@@ -133,6 +142,7 @@ class StateDisplay extends LitElement { | |||
<ha-relative-time | |||
.hass=${this.hass} | |||
.datetime=${relativeDateTime} | |||
.format=${this.format} |
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.
This would not be used ever, as we already would have returned the content === state
part?
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.
I have to check this, but I'm pretty sure I saw this being reached at some point during my testing. I'll investigate a bit more and provide any pertinent data.
Proposed change
This change adds the ability to use alternative (i.e. shorter) forms for time values where
state-display
is used. My primary goal was to make my badges that showed relative time a bit more concise. However, I think it could be generally useful anywhere that these formatted time strings are used (hence the expansion to the tile card).I'm not really sold on the name of the property though;
time_verbosity
seems a bit clunky. Perhapstime_format
orrelative_time_format
are more appropriate. I originally avoided those names because I did see a few other time-format-related props and didn't want to add confusion. If you have a better name for this property, I'd be more than happy to change it!Also, I wanted to bring up the fact that the positional arguments to
relativeTime
are becoming more unwieldy with this addition. I thought about migrating to named props, butrelativeTime
is used somewhat extensively throughout the codebase and I didn't want to introduce such a large change without getting feedback from the team first.Other thoughts:
state_content
pieces.Type of change
Example configuration
Badge config (also works on
tile
cards):Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: