From 111c2e1ae3369279edf0965b50a6bc986548c62c Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Mon, 23 Jul 2018 09:49:00 -0700 Subject: [PATCH] Fix Clocks module to recognize location identifiers with spaces in them Example: "America/New York" now works properly (internally it converts that string to "America/New_York" per https://golang.org/pkg/time/#LoadLocation). --- clocks/widget.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clocks/widget.go b/clocks/widget.go index 551ebda7..2d124bcd 100644 --- a/clocks/widget.go +++ b/clocks/widget.go @@ -1,6 +1,7 @@ package clocks import ( + "strings" "time" "github.com/senorprogrammer/wtf/wtf" @@ -35,7 +36,7 @@ func (widget *Widget) buildClockCollection(locData map[string]interface{}) Clock clockColl := ClockCollection{} for label, locStr := range locData { - timeLoc, err := time.LoadLocation(locStr.(string)) + timeLoc, err := time.LoadLocation(widget.sanitizeLocation(locStr.(string))) if err != nil { continue } @@ -45,3 +46,7 @@ func (widget *Widget) buildClockCollection(locData map[string]interface{}) Clock return clockColl } + +func (widget *Widget) sanitizeLocation(locStr string) string { + return strings.Replace(locStr, " ", "_", -1) +}