Bugfix
All checks were successful
release-tag / release-image (push) Successful in 2m13s

This commit is contained in:
2026-04-27 19:50:57 +02:00
parent f96b6cb306
commit 1c0d44b834

23
main.go
View File

@@ -1667,7 +1667,7 @@ func main() {
if t.IsZero() {
return ""
}
return utcDBTime(t).In(loc).Format("2006-01-02 15:04:05 MST")
return normalizeTime(t).In(loc).Format("2006-01-02 15:04:05 MST")
},
"short": func(s string, n int) string {
if len(s) <= n {
@@ -1739,11 +1739,30 @@ func main() {
}
}
func utcDBTime(t time.Time) time.Time {
func normalizeTime(t time.Time) time.Time {
if t.IsZero() {
return t
}
// Fall 1:
// MySQL DATETIME wird mit loc=UTC gelesen.
// Dann ist t.Location() bereits UTC und alles ist gut.
if t.Location() == time.UTC {
return t
}
// Fall 2:
// Der MySQL-Treiber hat die Zeit bereits als echten Zeitpunkt mit Location gelesen.
// Dann NICHT die Uhrzeit neu als UTC interpretieren, sondern Instant nach UTC konvertieren.
name := t.Location().String()
if name != "" && name != "Local" {
return t.UTC()
}
// Fall 3:
// MySQL DATETIME ohne echte Zeitzone wurde als time.Local interpretiert.
// In deiner Anwendung speicherst du DB-Zeiten logisch als UTC.
// Deshalb interpretieren wir die Wandzeit als UTC.
return time.Date(
t.Year(),
t.Month(),