hako / durafmt

:clock8: Better time duration formatting in Go!
MIT License
496 stars 49 forks source link

Feature: set significant figures #19

Open bruce-ricard opened 4 years ago

bruce-ricard commented 4 years ago

Hello,

I would like to be able NOT to use multiple different time units, but only one. For example, instead of 3 seconds 123 milliseconds, I'd like to get 3.123 seconds. I think it is easier to read this way. Even instead of 1 hour 30 minutes, I'd rather see 1.5 hours.

I would like to be able to, similarly to the function LimitFirstN, set the number of significant figures. A good name for the function could be WithSignificantFigures(int i). For example, if you set it to 3: 13 minutes 33 seconds would become 13.5 minutes. 3 minutes 15 seconds would become 3.25 minutes.

I would like to be able to print the international symbols of the time unit instead of their English word:

hour: h minute: min second: s millisecond: ms etc.

The thing I would ideally get for 1 second 234 milliseconds is 1.2s.

I am happy to try to make PRs for these 3 features. Would you be happy to accept them? Thank you.

hako commented 4 years ago

Hey, @bruce-ricard, This is a very useful feature, I would be happy to accept your PR as long as they have some tests.