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

Limit to adjacent time units #33

Open
alexjurkiewicz opened this issue Sep 21, 2022 · 0 comments
Open

Limit to adjacent time units #33

alexjurkiewicz opened this issue Sep 21, 2022 · 0 comments

Comments

@alexjurkiewicz
Copy link

I'd like a way to limit duration strings to the first N adjacent time units.

Existing behaviour:

package main

import (
	"fmt"
	"time"

	"github.com/hako/durafmt"
)

func main() {
	duration := durafmt.Parse(2*time.Hour + 58*time.Second).LimitFirstN(2).String()
	fmt.Println(duration)
}

This returns 2 hours 58 seconds.

I don't love this behaviour because the "58 seconds" part is not important and should be truncated. But if I had 58 minutes, that would be important.

Desired behaviour:

	duration := durafmt.Parse(2*time.Hour + 58*time.Second).LimitFirstAdjacentN(2).String()

Would return 2 hours.

	duration := durafmt.Parse(2*time.Hour + 15*time.Minute).LimitFirstAdjacentN(2).String()

Would return 2 hours 15 minutes.

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

No branches or pull requests

1 participant