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

ParseShort is not working as expected #24

Open
Dentrax opened this issue Nov 12, 2020 · 2 comments
Open

ParseShort is not working as expected #24

Dentrax opened this issue Nov 12, 2020 · 2 comments
Labels

Comments

@Dentrax
Copy link

Dentrax commented Nov 12, 2020

Since this prints: 9 years 46 weeks

durafmt.Parse(t).LimitFirstN(2).String()

I expected the ParseShort() function to print this way: 9y 46w

durafmt.ParseShort(t).LimitFirstN(2).String()

Am I missing something? If so, can we use custom formatting on these? (LONG, SHORT, etc.)

@hako
Copy link
Owner

hako commented Mar 16, 2021

@Dentrax apologies for the delay, is there a full code sample so that i can reproduce this?

@hako hako added the bug label Mar 16, 2021
@Dentrax
Copy link
Author

Dentrax commented Mar 17, 2021

@hako I created a simple code snippet to reproduce:

package main

import (
	"time"
	"github.com/hako/durafmt"
)

func main() {
	d := (354 * time.Hour) + (22 * time.Minute) + (3 * time.Second)

	println(durafmt.Parse(d).LimitFirstN(2).String())
	// Expected: 2 weeks 18 hours
	// Actual:   2 weeks 18 hours

	println(durafmt.ParseShort(d).LimitFirstN(2).String())
	// Expected: 2w 18h or 2 w 18 h
	// Actual:   2 weeks 18 hours
}

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

No branches or pull requests

2 participants