mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Really add timezone keys this time, because I totally botched that rebase earlier. A better man would go back and fix that; I... am not that man tonight.
This commit is contained in:
parent
e74302104a
commit
645552ae61
@ -4,16 +4,17 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Timezones(zones []string) []time.Time {
|
func Timezones(timezones map[string]interface{}) map[string]time.Time {
|
||||||
times := []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 {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
times = append(times, time.Now().In(loc))
|
times[label] = time.Now().In(tzloc)
|
||||||
}
|
}
|
||||||
|
|
||||||
return times
|
return times
|
||||||
|
@ -2,6 +2,7 @@ package status
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -61,16 +62,25 @@ func (widget *Widget) animation() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) timezones() 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 ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
formattedTimes := []string{}
|
// All this is to display the time entries in alphabetical order
|
||||||
for _, time := range times {
|
labels := []string{}
|
||||||
formattedTimes = append(formattedTimes, time.Format(wtf.TimeFormat))
|
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, " ◦ ")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user