Skip to content

Commit

Permalink
"15" is the correct 24 hours time format in go (qax-os#839)
Browse files Browse the repository at this point in the history
* "15" is the correct 24 hours time format in go
* fix number format convert issue and remove the `dateTimeFormatsCache`
  • Loading branch information
lfq7413 authored May 14, 2021
1 parent 5923c13 commit 1a84953
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, "[") {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down

0 comments on commit 1a84953

Please sign in to comment.