Skip to content

Commit

Permalink
Display the since date in the HIBP widget title
Browse files Browse the repository at this point in the history
  • Loading branch information
senorprogrammer committed Jun 22, 2019
1 parent 6216076 commit 8ce2242
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion modules/hibp/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ func (widget *Widget) Fetch(accounts []string) ([]*Status, error) {
func (widget *Widget) Refresh() {
data, err := widget.Fetch(widget.settings.accounts)

title := widget.CommonSettings.Title
title = title + widget.sinceDateForTitle()

var content string
if err != nil {
content = err.Error()
} else {
content = widget.contentFrom(data)
}

widget.Redraw(widget.CommonSettings.Title, content, false)
widget.Redraw(title, content, false)
}

/* -------------------- Unexported Functions -------------------- */
Expand All @@ -74,3 +77,22 @@ func (widget *Widget) contentFrom(data []*Status) string {

return str
}

func (widget *Widget) sinceDateForTitle() string {
dateStr := ""

if widget.settings.HasSince() {
sinceStr := ""

dt, err := widget.settings.SinceDate()
if err != nil {
sinceStr = widget.settings.since
} else {
sinceStr = dt.Format("Jan _2, 2006")
}

dateStr = dateStr + " since " + sinceStr
}

return dateStr
}

0 comments on commit 8ce2242

Please sign in to comment.