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

Clock is now actually a clock and not a snapshot in time

This commit is contained in:
Chris Cummer 2018-05-15 13:14:35 -07:00
parent a729b33ea9
commit 9f59ee1f9f
4 changed files with 35 additions and 17 deletions

View File

@ -1,11 +1,33 @@
package clocks
import(
import (
"time"
"github.com/senorprogrammer/wtf/wtf"
)
type Clock struct {
Label string
LocalTime time.Time
Timezone string
Location *time.Location
}
func NewClock(label string, timeLoc *time.Location) Clock {
clock := Clock{
Label: label,
Location: timeLoc,
}
return clock
}
func (clock *Clock) Date() string {
return clock.LocalTime().Format(wtf.SimpleDateFormat)
}
func (clock *Clock) LocalTime() time.Time {
return time.Now().In(clock.Location)
}
func (clock *Clock) Time() string {
return clock.LocalTime().Format(wtf.SimpleTimeFormat)
}

View File

@ -32,6 +32,6 @@ func (clocks *ClockCollection) SortedChronologically() {
clock := clocks.Clocks[i]
other := clocks.Clocks[j]
return clock.LocalTime.Before(other.LocalTime)
return clock.LocalTime().Before(other.LocalTime())
})
}

View File

@ -18,8 +18,8 @@ func (widget *Widget) display(clocks []Clock) {
" [%s]%-12s %-10s %7s[white]\n",
wtf.RowColor("clocks", idx),
clock.Label,
clock.LocalTime.Format(wtf.SimpleTimeFormat),
clock.LocalTime.Format(wtf.SimpleDateFormat),
clock.Time(),
clock.Date(),
)
}

View File

@ -12,6 +12,8 @@ var Config *config.Config
type Widget struct {
wtf.TextWidget
clockColl ClockCollection
}
func NewWidget() *Widget {
@ -19,6 +21,8 @@ func NewWidget() *Widget {
TextWidget: wtf.NewTextWidget(" 🕗 World Clocks ", "clocks", false),
}
widget.clockColl = widget.buildClockCollection(Config.UMap("wtf.mods.clocks.locations"))
return &widget
}
@ -29,10 +33,8 @@ func (widget *Widget) Refresh() {
return
}
clockColl := widget.buildClockCollection(Config.UMap("wtf.mods.clocks.locations"))
widget.View.Clear()
widget.display(clockColl.Sorted())
widget.display(widget.clockColl.Sorted())
widget.RefreshedAt = time.Now()
}
@ -47,13 +49,7 @@ func (widget *Widget) buildClockCollection(locData map[string]interface{}) Clock
continue
}
clock := Clock{
Label: label,
LocalTime: time.Now().In(timeLoc),
Timezone: locStr.(string),
}
clockColl.Clocks = append(clockColl.Clocks, clock)
clockColl.Clocks = append(clockColl.Clocks, NewClock(label, timeLoc))
}
return clockColl