diff options
author | ice <lfq7413@gmail.com> | 2021-05-14 13:01:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-14 13:01:08 +0800 |
commit | 37342f6d81b27adbcdc6cf6cf9ccdc68f92cdb46 (patch) | |
tree | 4878e9dea9704a3c4dc586149e9bbd0ed64b45b5 /styles.go | |
parent | a1e1db1e6f2faa8286afb1e9291c51fa084b66f7 (diff) |
"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`
Diffstat (limited to 'styles.go')
-rw-r--r-- | styles.go | 22 |
1 files changed, 10 insertions, 12 deletions
@@ -934,8 +934,6 @@ func formatToE(v string, format string) string { return fmt.Sprintf("%.e", f) } -var dateTimeFormatsCache = map[string]string{} - // parseTime provides a function to returns a string parsed using time.Time. // 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 @@ -963,11 +961,6 @@ func parseTime(v string, format string) string { return v } - goFmt, found := dateTimeFormatsCache[format] - if found { - return val.Format(goFmt) - } - goFmt = format if strings.Contains(goFmt, "[") { @@ -1023,9 +1016,17 @@ func parseTime(v string, format string) string { goFmt = strings.Replace(goFmt, "H", "3", 1) } else { 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, "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 { @@ -1045,9 +1046,6 @@ func parseTime(v string, format string) string { goFmt = strings.Replace(goFmt, "[3]", "3", 1) goFmt = strings.Replace(goFmt, "[15]", "15", 1) } - - dateTimeFormatsCache[format] = goFmt - return val.Format(goFmt) } |