"15" is the correct 24 hours time format in go (#839)

* "15" is the correct 24 hours time format in go
* fix number format convert issue and remove the `dateTimeFormatsCache`
This commit is contained in:
ice 2021-05-14 13:01:08 +08:00 committed by GitHub
parent a1e1db1e6f
commit 37342f6d81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 12 deletions

View File

@ -934,8 +934,6 @@ func formatToE(v string, format string) string {
return fmt.Sprintf("%.e", f) return fmt.Sprintf("%.e", f)
} }
var dateTimeFormatsCache = map[string]string{}
// parseTime provides a function to returns a string parsed using time.Time. // parseTime provides a function to returns a string parsed using time.Time.
// Replace Excel placeholders with Go time placeholders. For example, replace // Replace Excel placeholders with Go time placeholders. For example, replace
// yyyy with 2006. These are in a specific order, due to the fact that m is // yyyy with 2006. These are in a specific order, due to the fact that m is
@ -963,11 +961,6 @@ func parseTime(v string, format string) string {
return v return v
} }
goFmt, found := dateTimeFormatsCache[format]
if found {
return val.Format(goFmt)
}
goFmt = format goFmt = format
if strings.Contains(goFmt, "[") { if strings.Contains(goFmt, "[") {
@ -1023,9 +1016,17 @@ func parseTime(v string, format string) string {
goFmt = strings.Replace(goFmt, "H", "3", 1) goFmt = strings.Replace(goFmt, "H", "3", 1)
} else { } else {
goFmt = strings.Replace(goFmt, "hh", "15", 1) goFmt = strings.Replace(goFmt, "hh", "15", 1)
goFmt = strings.Replace(goFmt, "h", "3", 1) if val.Hour() < 12 {
goFmt = strings.Replace(goFmt, "h", "3", 1)
} else {
goFmt = strings.Replace(goFmt, "h", "15", 1)
}
goFmt = strings.Replace(goFmt, "HH", "15", 1) goFmt = strings.Replace(goFmt, "HH", "15", 1)
goFmt = strings.Replace(goFmt, "H", "3", 1) if val.Hour() < 12 {
goFmt = strings.Replace(goFmt, "H", "3", 1)
} else {
goFmt = strings.Replace(goFmt, "H", "15", 1)
}
} }
for _, repl := range replacements { for _, repl := range replacements {
@ -1045,9 +1046,6 @@ func parseTime(v string, format string) string {
goFmt = strings.Replace(goFmt, "[3]", "3", 1) goFmt = strings.Replace(goFmt, "[3]", "3", 1)
goFmt = strings.Replace(goFmt, "[15]", "15", 1) goFmt = strings.Replace(goFmt, "[15]", "15", 1)
} }
dateTimeFormatsCache[format] = goFmt
return val.Format(goFmt) return val.Format(goFmt)
} }