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

Create option to humanize time output #2080

Open
mmarras opened this issue Nov 26, 2024 · 3 comments · May be fixed by #2094
Open

Create option to humanize time output #2080

mmarras opened this issue Nov 26, 2024 · 3 comments · May be fixed by #2094

Comments

@mmarras
Copy link

mmarras commented Nov 26, 2024

This touches on #1459.

I am (again) trying to get a human friendly version of a time. Somewhat with the same intention why https://pypi.org/project/humanize/ exists.

Background is that I want to show time data in a human friendly way. ks, Ms etc are not helpful here.

102123123 s, very few humans will be able to comprehend. I can do ureg.Quantity('102123123 s').to_compact() and get 102.12... Ms. So how long is that again? Only when I do ureg.Quantity('102123123 s').to('a') and get 3.23…. a, I can appreaciate what that time means. However, I will have to know a-priory what the meaningful time-unit is to convert into for this particular case. But if I got 0.323 years as result it would not be a nice result either. It's just not how we are used to think about time. When dealing with large fractions of a year I expect the results in months (0.323 years are 3.87 month).

I am proposing to create a modification of to_compact which will automatically convert units of dimension [time] to a suitable humanfriendly time unit. Suitable time unit in my opinion (but that's possibly up for debate) is the time unit which leaves the magnitude with at least one, but the least amount of integer parts. So the time unit should be the "biggest" which doesn't leave the magnitude to be purely fractional so no 0.XXX years (because then I want months!), but 1.212 years is fine.

Example:

1001 ms should convert to 1.001 s
59 s should still be 59 s
but 60 s should be 1.0 min
61 min should be 1.01... h
and so on.
I'm not sure if pint implements a decade but it does implement a century
so finally
ureg.Quantity('10231231232s ').to_compact(humantime=True) -> 3.23 century
(again millenium seem not to be implemented, eon is, maybe that's another topic to pick up: https://en.wikipedia.org/wiki/Unit_of_time, but not to dilute this post).

As demonstrated above, to_compact(), to_preferred() and to_base_units() are related but don't get the job done out of the box.

@andrewgsavage
Copy link
Collaborator

andrewgsavage commented Nov 26, 2024 via email

@mmarras
Copy link
Author

mmarras commented Nov 26, 2024

So I guess one way to go about is to get all units of dimension [time] in the registry. Then rank them by “size” and then start at the lowest one until we get the first non-zero integer part.
would that be flexible enough?

@andrewgsavage
Copy link
Collaborator

andrewgsavage commented Nov 26, 2024 via email

@andrewgsavage andrewgsavage linked a pull request Dec 16, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants