diff --git a/status/timezones.go b/status/timezones.go new file mode 100644 index 00000000..0ffd2d8b --- /dev/null +++ b/status/timezones.go @@ -0,0 +1,20 @@ +package status + +import ( + "time" +) + +func Timezones(zones []string) []time.Time { + times := []time.Time{} + + for _, zone := range zones { + loc, err := time.LoadLocation(zone) + if err != nil { + continue + } + + times = append(times, time.Now().In(loc)) + } + + return times +} diff --git a/status/widget.go b/status/widget.go index eef0f128..0955eff1 100644 --- a/status/widget.go +++ b/status/widget.go @@ -2,6 +2,7 @@ package status import ( "fmt" + "strings" "time" "github.com/gdamore/tcell" @@ -40,7 +41,12 @@ func (widget *Widget) Refresh() { widget.RefreshedAt = time.Now() widget.View.Clear() - fmt.Fprintf(widget.View, " %s", widget.contentFrom()) + fmt.Fprintf( + widget.View, + "%107s\n%123s", + widget.animation(), + widget.timezones(), + ) } /* -------------------- Unexported Functions -------------------- */ @@ -52,11 +58,12 @@ func (widget *Widget) addView() { view.SetBorderColor(tcell.ColorGray) view.SetDynamicColors(true) view.SetTitle(widget.Name) + view.SetWrap(false) widget.View = view } -func (widget *Widget) contentFrom() string { +func (widget *Widget) animation() string { icons := []string{"👍", "🤜", "🤙", "🤜", "🤘", "🤜", "✊", "🤜", "👌", "🤜"} next := icons[widget.Current] @@ -67,3 +74,18 @@ func (widget *Widget) contentFrom() string { return next } + +func (widget *Widget) timezones() string { + times := Timezones(wtf.ToStrs(Config.UList("wtf.mods.status.timezones"))) + + if len(times) == 0 { + return "" + } + + formattedTimes := []string{} + for _, time := range times { + formattedTimes = append(formattedTimes, time.Format(wtf.TimeFormat)) + } + + return strings.Join(formattedTimes, " [yellow]•[white] ") +} diff --git a/wtf/utils.go b/wtf/utils.go index 89dd0440..4bb486ba 100644 --- a/wtf/utils.go +++ b/wtf/utils.go @@ -10,6 +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" func CenterText(str string, width int) string { return fmt.Sprintf("%[1]*s", -width, fmt.Sprintf("%[1]*s", (width+len(str))/2, str)) @@ -89,6 +90,15 @@ func ToInts(slice []interface{}) []int { return results } +func ToStrs(slice []interface{}) []string { + results := []string{} + for _, val := range slice { + results = append(results, val.(string)) + } + + return results +} + func UnixTime(unix int64) time.Time { return time.Unix(unix, 0) }