mirror of
https://gitee.com/dromara/carbon.git
synced 2024-11-29 18:57:37 +08:00
optimization logic
This commit is contained in:
parent
fff03395c8
commit
89e8cfbdc0
@ -4,7 +4,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gitee.com/go-package/carbon/lang"
|
||||
"gitee.com/golang-package/carbon/lang"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -67,8 +67,8 @@ func (l *Language) translate(unit string, number int64) string {
|
||||
if len(slice) == 1 {
|
||||
return strings.Replace(slice[0], "%d", strconv.FormatInt(number, 10), 1)
|
||||
}
|
||||
if number > 1 {
|
||||
return strings.Replace(slice[1], "%d", strconv.FormatInt(number, 10), 1)
|
||||
if int64(len(slice)) <= number {
|
||||
return strings.Replace(slice[len(slice)-1], "%d", strconv.FormatInt(number, 10), 1)
|
||||
}
|
||||
return slice[0]
|
||||
return strings.Replace(slice[number-1], "%d", strconv.FormatInt(number, 10), 1)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user