diff --git a/status/timezones.go b/status/timezones.go index 0ffd2d8b..8a9a5a48 100644 --- a/status/timezones.go +++ b/status/timezones.go @@ -4,16 +4,17 @@ import ( "time" ) -func Timezones(zones []string) []time.Time { - times := []time.Time{} +func Timezones(timezones map[string]interface{}) map[string]time.Time { + times := make(map[string]time.Time) + + for label, timezone := range timezones { + tzloc, err := time.LoadLocation(timezone.(string)) - for _, zone := range zones { - loc, err := time.LoadLocation(zone) if err != nil { continue } - times = append(times, time.Now().In(loc)) + times[label] = time.Now().In(tzloc) } return times diff --git a/status/widget.go b/status/widget.go index 5ba66cf3..29d689bd 100644 --- a/status/widget.go +++ b/status/widget.go @@ -2,6 +2,7 @@ package status import ( "fmt" + "sort" "strings" "time" @@ -61,16 +62,25 @@ func (widget *Widget) animation() string { } func (widget *Widget) timezones() string { - times := Timezones(wtf.ToStrs(Config.UList("wtf.mods.status.timezones"))) + timezones := Timezones(Config.UMap("wtf.mods.status.timezones")) - if len(times) == 0 { + if len(timezones) == 0 { return "" } - formattedTimes := []string{} - for _, time := range times { - formattedTimes = append(formattedTimes, time.Format(wtf.TimeFormat)) + // All this is to display the time entries in alphabetical order + labels := []string{} + for label, _ := range timezones { + labels = append(labels, label) } - return strings.Join(formattedTimes, " • ") + sort.Strings(labels) + + tzs := []string{} + for _, label := range labels { + zoneStr := fmt.Sprintf("%s %s", label, timezones[label].Format(wtf.TimeFormat)) + tzs = append(tzs, zoneStr) + } + + return strings.Join(tzs, " ◦ ") }