From 80d618347ed2d70530c8486ef60fb5dcf8b89473 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Thu, 31 Mar 2022 04:02:49 +0400 Subject: [PATCH] Oh, oops. range copies values, that's why nothing happens. Use good old for now. --- internal/handlers/handlers.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 485df61..3bed37e 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -76,6 +76,12 @@ func (h *RadioHandlers) Index(w http.ResponseWriter, r *http.Request) { status.ServerStartISO8601 = utils.ToClientTimezone(tim, r).Format(FormatISO8601) } + for i := 0; i < len(songs); i++ { + if tim, err := time.Parse("15:04-0700", songs[i].Time); err == nil { + songs[i].Time = utils.ToClientTimezone(tim, r).Format("15:04") + } + } + if err := compiledTemplates["index"].Execute(w, &IndexData{ MainSite: utils.MainSite(r.Host), Status: status, @@ -117,13 +123,8 @@ func (h *RadioHandlers) LastSong(w http.ResponseWriter, r *http.Request) { return } - for _, song := range songs { - tim, err := time.Parse("15:04-0700", song.Time) - if err == nil { - song.Time = utils.ToClientTimezone(tim, r).Format("15:04") - } else { - h.logErr.Println("song time parse error:", err) - } + if tim, err := time.Parse("15:04-0700", songs[0].Time); err == nil { + songs[0].Time = utils.ToClientTimezone(tim, r).Format("15:04") } w.Header().Add("Content-Type", "application/json")