-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Missing option to display years and months when years > 1 #108
Comments
What it's doing is rounding to years, when years >= 2: >>> import humanize
>>> from datetime import timedelta
>>> for year in range(5):
... humanize.naturaldelta(timedelta(days=(year+0.6) * 365), months=True)
...
'7 months'
'1 year, 7 months'
'2 years'
'3 years'
'4 years' And similarly with >>> for year in range(5):
... humanize.naturaldelta(timedelta(days=(year+0.6) * 365), months=False)
...
'219 days'
'1 year, 219 days'
'2 years'
'3 years'
'4 years' And likewise for >>> for year in range(5):
... humanize.naturaltime(timedelta(days=(year+0.6) * 365), months=True)
...
'7 months ago'
'1 year, 7 months ago'
'2 years ago'
'3 years ago'
'4 years ago'
>>> for year in range(5):
... humanize.naturaltime(timedelta(days=(year+0.6) * 365), months=False)
...
'219 days ago'
'1 year, 219 days ago'
'2 years ago'
'3 years ago'
'4 years ago' So |
Hi @hugovk! Thank you for the explanation. My use case is that we need to display the amortization of an investment. Currently it says "4.6 years" and I thought I could use humanize to turn it into something like "4 years, 7 months" because that's more human friendly. There's a way to do this using a hack:
The problem with this is that it might break translations. |
I guess one idea is to add a new option to make the cutoff configurable, and (I expect) use it to replace the 1 in That would also require a lot more handling in that block to deal with singular and plural years, especially for the translations. |
Would like to chime in here. I would like to see naturaldelta behavior to be..
>>> delta = dt.timedelta(seconds=36, minutes=3)
>>> humanize.naturaldelta(delta) should allow for either
This is a default output format in kubernetes client to show the age. It always shows 2 units (unless we are in seconds) ❯ kubectl get deployments -A
NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGE
kube-system coredns 2/2 2 2 6d14h
local-path-storage local-path-provisioner 1/1 1 1 6d14h
❯ kubectl get pod
NAME READY STATUS RESTARTS AGE
temp 1/1 Running 0 18s
❯ kubectl get pod
NAME READY STATUS RESTARTS AGE
temp 1/1 Running 0 105s
❯ kubectl get pod
NAME READY STATUS RESTARTS AGE
temp 1/1 Running 0 2m4s Logic for above calculation is here. |
What did you do?
What did you expect to happen?
What actually happened?
see above
What versions are you using?
How to fix?
The text was updated successfully, but these errors were encountered: