1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Merge branch '10-timezone-labels'

This commit is contained in:
Chris Cummer 2018-04-15 18:03:27 -07:00 committed by Chris Cummer
commit e74302104a
4 changed files with 12 additions and 24 deletions

View File

@ -4,17 +4,16 @@ import (
"time" "time"
) )
func Timezones(timezones map[string]interface{}) map[string]time.Time { func Timezones(zones []string) []time.Time {
times := make(map[string]time.Time) times := []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[label] = time.Now().In(tzloc) times = append(times, time.Now().In(loc))
} }
return times return times

View File

@ -2,7 +2,6 @@ package status
import ( import (
"fmt" "fmt"
"sort"
"strings" "strings"
"time" "time"
@ -62,25 +61,16 @@ func (widget *Widget) animation() string {
} }
func (widget *Widget) timezones() string { func (widget *Widget) timezones() string {
timezones := Timezones(Config.UMap("wtf.mods.status.timezones")) times := Timezones(wtf.ToStrs(Config.UList("wtf.mods.status.timezones")))
if len(timezones) == 0 { if len(times) == 0 {
return "" return ""
} }
// All this is to display the time entries in alphabetical order formattedTimes := []string{}
labels := []string{} for _, time := range times {
for label, _ := range timezones { formattedTimes = append(formattedTimes, time.Format(wtf.TimeFormat))
labels = append(labels, label)
} }
sort.Strings(labels) return strings.Join(formattedTimes, " • ")
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, " ◦ ")
} }

View File

@ -28,7 +28,6 @@ func LoadConfigFile(filePath string) *config.Config {
cfg, err := config.ParseYamlFile(absPath) cfg, err := config.ParseYamlFile(absPath)
if err != nil { 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("\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) os.Exit(1)
} }

View File

@ -10,7 +10,7 @@ import (
// DateFormat defines the format we expect to receive dates from BambooHR in // DateFormat defines the format we expect to receive dates from BambooHR in
const DateFormat = "2006-01-02" const DateFormat = "2006-01-02"
const TimeFormat = "15:04" const TimeFormat = "15:04 MST"
func CenterText(str string, width int) string { func CenterText(str string, width int) string {
return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str)) return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str))