Open flxo opened 1 year ago
I would find this feature very useful as well.
Perhaps for logging it would then be even more useful to allow a duration to be formatted to only the most significant precision, i.e. if more than an hour in terms of hours, if more than a minute but less than hours in terms of minutes, etc. For application where precision is not required and you wish to give the user only a rough indication of time, like for some logging cases I think only the most significant time indicator would be the easiest to read.
Thanks for the workaround, I came into the crate's repo to find how to do just this.
This could use the Formatter::precision
, e.g. format!("{0:.1} | {0:.2} | {0}", humantime::format_duration(Duration::from_secs(3661)))
could be "1h | 1h 1m | 1h 1m 1s"
.
Sometimes displaying durations in their full precision is not needed and counter productive. Especially in logs where the quantity of a duration is in a seconds/minute/hour range the formatting of
ms
,us
andns
might want to be omitted.The boilerplate workaround I did some times is (beside creating a trait and blah blah...) is to do something like
to get rid of the subsec part.
A possible extension could look like
If applicable I happily file a PR.
thanks