xhit/go-str2duration

Proposal: Add String function that prints out days and weeks

Closed this issue ยท 5 comments

This is the current situation:

t, _ := str2duration.ParseDuration("2w")
fmt.Println(t.String()) // 672h0m0s

It would be nice to have str2duration.String(t time.Duration) string:

t, _ := str2duration.ParseDuration("2w")
fmt.Println(str2duration.String(t)) // 2w

Or to align with Go's output format (but that looks rather ugly):

t, _ := str2duration.ParseDuration("2w")
fmt.Println(str2duration.String(t)) // 2w0d0h0m0s
xhit commented

Sounds good!

If you want to I can give a naive PR a try?

xhit commented

Hi Lukas, I have an implementation for this, currently is the long format 2w0d0h0m0s but I is possible return the short form 2w, I need to go home to make a PR. Thanks for the interest to contribute, I hope this will be released in this week.

xhit commented

Added in v2.1.0, thanks for the proposal Lukas ๐Ÿš€

Damn, that was fast! Nice one and thank you!