Skip to content

Commit

Permalink
typo: gtime locale
Browse files Browse the repository at this point in the history
  • Loading branch information
xjh22222228 committed Mar 12, 2021
1 parent 09e2510 commit 1a80ecf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions gtime/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ type Gtime struct {

const regex = `\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS`

func GetLocale(l locale.Language) *locale.Locale {
switch l {
case locale.LEN:
return locale.EnUS
case locale.LZH:
return locale.ZhCN
}
return locale.EnUS
}

func SetLocale(language locale.Language) *Gtime {
return &Gtime{
Language: language,
Expand All @@ -45,7 +35,7 @@ func (that Gtime) SetLocale(language locale.Language) *Gtime {
}

func Format(t time.Time, format string) string {
return formatTime(t, format, locale.LEN)
return formatTime(t, format, locale.ENUS)
}

// | Format| Output | Description |
Expand Down Expand Up @@ -75,7 +65,7 @@ func Format(t time.Time, format string) string {
// | a | am pm | |
func formatTime(t time.Time, format string, language locale.Language) string {
r := regexp.MustCompile(regex)
intl := GetLocale(language)
intl := getLocale(language)
y, m, d := t.Date()

year := strconv.Itoa(y)
Expand Down Expand Up @@ -137,6 +127,16 @@ func formatTime(t time.Time, format string, language locale.Language) string {
return v
}

func getLocale(l locale.Language) *locale.Locale {
switch l {
case locale.ENUS:
return locale.EnUS
case locale.ZHCN:
return locale.ZhCN
}
return locale.EnUS
}

func hourTo12(n int) int {
if n > 13 {
return n - 12
Expand Down
4 changes: 2 additions & 2 deletions gtime/locale/locale.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Locale struct {
type Language int

const (
LZH Language = 1 + iota
LEN
ZHCN Language = 1 + iota
ENUS
)

0 comments on commit 1a80ecf

Please sign in to comment.