"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:
parent
a1e1db1e6f
commit
37342f6d81
22
styles.go
22
styles.go
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue