mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Allow custom date and time formats for clocks
This commit is contained in:
parent
eb7da5131e
commit
e8ef4800f8
@ -2,8 +2,6 @@ package clocks
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
type Clock struct {
|
||||
@ -20,8 +18,8 @@ func NewClock(label string, timeLoc *time.Location) Clock {
|
||||
return clock
|
||||
}
|
||||
|
||||
func (clock *Clock) Date() string {
|
||||
return clock.LocalTime().Format(wtf.SimpleDateFormat)
|
||||
func (clock *Clock) Date(dateFormat string) string {
|
||||
return clock.LocalTime().Format(dateFormat)
|
||||
}
|
||||
|
||||
func (clock *Clock) LocalTime() time.Time {
|
||||
@ -32,6 +30,6 @@ func (clock *Clock) ToLocal(t time.Time) time.Time {
|
||||
return t.In(clock.Location)
|
||||
}
|
||||
|
||||
func (clock *Clock) Time() string {
|
||||
return clock.LocalTime().Format(wtf.SimpleTimeFormat)
|
||||
func (clock *Clock) Time(timeFormat string) string {
|
||||
return clock.LocalTime().Format(timeFormat)
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
func (widget *Widget) display(clocks []Clock) {
|
||||
func (widget *Widget) display(clocks []Clock, dateFormat string, timeFormat string) {
|
||||
if len(clocks) == 0 {
|
||||
widget.View.SetText(fmt.Sprintf("\n%s", " no timezone data available"))
|
||||
return
|
||||
@ -18,8 +18,8 @@ func (widget *Widget) display(clocks []Clock) {
|
||||
" [%s]%-12s %-10s %7s[white]\n",
|
||||
wtf.RowColor("clocks", idx),
|
||||
clock.Label,
|
||||
clock.Time(),
|
||||
clock.Date(),
|
||||
clock.Time(timeFormat),
|
||||
clock.Date(dateFormat),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,8 @@ type Widget struct {
|
||||
wtf.TextWidget
|
||||
|
||||
clockColl ClockCollection
|
||||
dateFormat string
|
||||
timeFormat string
|
||||
}
|
||||
|
||||
func NewWidget(app *tview.Application) *Widget {
|
||||
@ -21,6 +23,9 @@ func NewWidget(app *tview.Application) *Widget {
|
||||
|
||||
widget.clockColl = widget.buildClockCollection(wtf.Config.UMap("wtf.mods.clocks.locations"))
|
||||
|
||||
widget.dateFormat = wtf.Config.UString("wtf.mods.clocks.dateFormat", wtf.SimpleDateFormat)
|
||||
widget.timeFormat = wtf.Config.UString("wtf.mods.clocks.timeFormat", wtf.SimpleTimeFormat)
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
@ -28,7 +33,7 @@ func NewWidget(app *tview.Application) *Widget {
|
||||
|
||||
func (widget *Widget) Refresh() {
|
||||
widget.UpdateRefreshedAt()
|
||||
widget.display(widget.clockColl.Sorted())
|
||||
widget.display(widget.clockColl.Sorted(), widget.dateFormat, widget.timeFormat)
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
Loading…
x
Reference in New Issue
Block a user