mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Timezone labels supported
This commit is contained in:
parent
0b20c4939e
commit
f0caaf3890
@ -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, " ◦ ")
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 MST"
|
const TimeFormat = "15:04"
|
||||||
|
|
||||||
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))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user