-
Notifications
You must be signed in to change notification settings - Fork 484
Description
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.