mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Hacky timezone display in Status
This commit is contained in:
parent
dd170c0ab3
commit
1bf6efdaf8
20
status/timezones.go
Normal file
20
status/timezones.go
Normal file
@ -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
|
||||
}
|
@ -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]Β ")
|
||||
}
|
||||
|
10
wtf/utils.go
10
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)
|
||||
}
|
||||
|
Loadingβ¦
x
Reference in New Issue
Block a user