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..64ec0a91 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, " ◦ ") } diff --git a/wtf/config_files.go b/wtf/config_files.go index eeb28c5d..a38b740a 100644 --- a/wtf/config_files.go +++ b/wtf/config_files.go @@ -28,6 +28,7 @@ func LoadConfigFile(filePath string) *config.Config { cfg, err := config.ParseYamlFile(absPath) if err != nil { fmt.Println("\n\n\033[1m ERROR:\033[0m Could not load '\033[0;33mconfig.yml\033[0m'.\n Please add a \033[0;33mconfig.yml\033[0m file to your \033[0;33m~/.wtf\033[0m directory.\n See \033[1;34mhttps://github.com/senorprogrammer/wtf\033[0m for details.\n\n") + fmt.Println(err.Error()) os.Exit(1) } diff --git a/wtf/utils.go b/wtf/utils.go index 4bb486ba..5832fcca 100644 --- a/wtf/utils.go +++ b/wtf/utils.go @@ -10,7 +10,7 @@ import ( // DateFormat defines the format we expect to receive dates from BambooHR in const DateFormat = "2006-01-02" -const TimeFormat = "15:04 MST" +const TimeFormat = "15:04" func CenterText(str string, width int) string { return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str))