mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Add Clocks module
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
package status
|
||||
|
||||
import (
|
||||
"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))
|
||||
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
times[label] = time.Now().In(tzloc)
|
||||
}
|
||||
|
||||
return times
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package status
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
//"fmt"
|
||||
//"sort"
|
||||
//"strings"
|
||||
"time"
|
||||
|
||||
"github.com/olebedev/config"
|
||||
@@ -35,15 +35,14 @@ func (widget *Widget) Refresh() {
|
||||
return
|
||||
}
|
||||
|
||||
// FIXME: Use two calls to wtf.RightAlign here and get rid of this code duplication
|
||||
_, _, w, _ := widget.View.GetInnerRect()
|
||||
//_, _, w, _ := widget.View.GetInnerRect()
|
||||
|
||||
widget.View.Clear()
|
||||
fmt.Fprintf(
|
||||
widget.View,
|
||||
fmt.Sprintf("\n%%%ds", w-1),
|
||||
widget.timezones(),
|
||||
)
|
||||
//widget.View.Clear()
|
||||
//fmt.Fprintf(
|
||||
//widget.View,
|
||||
//fmt.Sprintf("\n%%%ds", w-1),
|
||||
//widget.timezones(),
|
||||
//)
|
||||
|
||||
widget.RefreshedAt = time.Now()
|
||||
}
|
||||
@@ -61,27 +60,3 @@ func (widget *Widget) animation() string {
|
||||
|
||||
return next
|
||||
}
|
||||
|
||||
func (widget *Widget) timezones() string {
|
||||
timezones := Timezones(Config.UMap("wtf.mods.status.timezones"))
|
||||
|
||||
if len(timezones) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
// All this is to display the time entries in alphabetical order
|
||||
labels := []string{}
|
||||
for label, _ := range timezones {
|
||||
labels = append(labels, label)
|
||||
}
|
||||
|
||||
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, " ◦ ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user