优化格式化星期值性能

This commit is contained in:
jroam
2019-04-22 13:55:53 +08:00
parent f1a9fbb74e
commit a800f731dd

View File

@ -10,6 +10,7 @@ import (
"bytes"
"github.com/gogf/gf/g/text/gregex"
"github.com/gogf/gf/g/text/gstr"
"strconv"
"strings"
)
@ -135,7 +136,7 @@ func (t *Time) Format(format string) string {
case 'u':
buffer.WriteString(strings.Replace(result, "=u=.", "", -1))
case 'w':
buffer.WriteString(weekstosint(result))
buffer.WriteString(strconv.Itoa(int(t.Weekday())))
default:
buffer.WriteString(result)
}
@ -152,19 +153,3 @@ func (t *Time) Format(format string) string {
func (t *Time) Layout(layout string) string {
return t.Time.Format(layout)
}
// 将字母的星期数字转为数字:0为星期天 6为星期六
func weekstosint(week string) string {
weeks := map[string]string{
"Monday": "1",
"Tuesday": "2",
"Wednesday": "3",
"Thursday": "4",
"Friday": "5",
"Saturday ": "6",
"Sunday": "0",
}
return weeks[week]
}