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

Allow customization of time format #22339

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

breakthestatic
Copy link
Contributor

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).

Screenshot 2024-10-11 at 3 03 46 PM

I'm not really sold on the name of the property though; time_verbosity seems a bit clunky. Perhaps time_format or relative_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, but relativeTime 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:

  • I think this is likely a more advanced use-case and should be YAML-only.
  • I don't think it needs to be configurable per state-item. The provided format should be used for all state_content pieces.
  • Documentation PR has not been created yet, as I wasn't sure if this PR would be accepted and if the form would change based on review comments.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Badge config (also works on tile cards):

type: entity
entity: sensor.sun_next_dusk
time_verbosity: narrow

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

@marcinbauer85
Copy link

This can be just in YAML and described in the documentation.

@karwosts
Copy link
Contributor

karwosts commented Nov 5, 2024

I'm not really sold on the name of the property though

What if you didn't make a new property at all, and just added options the existing format property? Could add relative_narrow or relative_short as additional options here.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants