Skip to content
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

Proposal: Add String function that prints out days and weeks #2

Closed
lukasmalkmus opened this issue Dec 5, 2022 · 5 comments · Fixed by #3
Closed

Proposal: Add String function that prints out days and weeks #2

lukasmalkmus opened this issue Dec 5, 2022 · 5 comments · Fixed by #3
Labels
enhancement New feature or request

Comments

@lukasmalkmus
Copy link

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
Copy link
Owner

xhit commented Dec 6, 2022

Sounds good!

@xhit xhit added the enhancement New feature or request label Dec 6, 2022
@lukasmalkmus
Copy link
Author

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

@xhit
Copy link
Owner

xhit commented Dec 6, 2022

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
Copy link
Owner

xhit commented Dec 7, 2022

Added in v2.1.0, thanks for the proposal Lukas 🚀

@lukasmalkmus
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants