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

Error using Chinese time units to output #34

Open
CHN-STUDENT opened this issue Apr 6, 2023 · 3 comments
Open

Error using Chinese time units to output #34

CHN-STUDENT opened this issue Apr 6, 2023 · 3 comments

Comments

@CHN-STUDENT
Copy link

package main

import (
	"fmt"

	"github.com/hako/durafmt"
)

func main() {
	str := "9999999s"
	units, _ := durafmt.DefaultUnitsCoder.Decode("年,周,天,时,分,秒,毫秒,微秒")
	duration, _ := durafmt.ParseString(str)
	fmt.Println(duration.Format(units)) //output: 16 周s 3 天s 17 时s 46 分s 39 秒s
 //correct:16 周3 天17 时 46 分39 秒
}

Because Chinese time units do not need sigular + 's' suffix
so i must use units, _ := durafmt.DefaultUnitsCoder.Decode("年:年,周:周,天:天,时:时,分:分,秒:秒,毫秒:毫秒,微秒:微秒") instead of

@TangMonk
Copy link

TangMonk commented May 27, 2023

兄弟,帮你搞定了

package main

import (
	"fmt"

	"github.com/hako/durafmt"
)

func main() {
	str := "9999999s"
	units, _ := durafmt.DefaultUnitsCoder.Decode("年:年,周:周,天:天,时:时,分:分,秒:秒,毫秒:毫秒,微秒:微秒")
	duration, _ := durafmt.ParseString(str)
	fmt.Println(duration.Format(units)) //output: 16 周s 3 天s 17 时s 46 分s 39 秒s
	//correct:16 周3 天17 时 46 分39 秒
}

@CHN-STUDENT
Copy link
Author

@TangMonk 对,这个包如果要使用中文时区需要自定时间单位,想问问作者有什么其他方案么

@TangMonk
Copy link

@TangMonk 对,这个包如果要使用中文时区需要自定时间单位,想问问作者有什么其他方案么

应该没了

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

2 participants