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

Mark the current calendar event if there is one

This commit is contained in:
Chris Cummer 2018-04-03 14:51:21 -07:00 committed by Chris Cummer
parent ef10ac5d0c
commit 12e6b2a9f2
3 changed files with 29 additions and 16 deletions

View File

@ -60,17 +60,41 @@ func (widget *Widget) addView() {
func (widget *Widget) contentFrom(events *calendar.Events) string { func (widget *Widget) contentFrom(events *calendar.Events) string {
str := "\n" str := "\n"
for _, item := range events.Items { for _, event := range events.Items {
startTime, _ := time.Parse(time.RFC3339, item.Start.DateTime) startTime, _ := time.Parse(time.RFC3339, event.Start.DateTime)
timestamp := startTime.Format("Mon, Jan 2, 15:04") timestamp := startTime.Format("Mon, Jan 2, 15:04")
until := widget.until(startTime) until := widget.until(startTime)
str = str + fmt.Sprintf(" [%s]%s[white]\n [%s]%s %s[white]\n\n", titleColor(item), item.Summary, descriptionColor(item), timestamp, until) summary := event.Summary
if widget.eventIsNow(event) {
summary = "πŸ”₯ " + summary
}
str = str + fmt.Sprintf(" [%s]%s[white]\n [%s]%s %s[white]\n\n", titleColor(event), summary, descriptionColor(event), timestamp, until)
} }
return str return str
} }
// eventIsNow returns true if the event is happening now, false if it not
func (widget *Widget) eventIsNow(event *calendar.Event) bool {
startTime, _ := time.Parse(time.RFC3339, event.Start.DateTime)
endTime, _ := time.Parse(time.RFC3339, event.End.DateTime)
return time.Now().After(startTime) && time.Now().Before(endTime)
}
func descriptionColor(item *calendar.Event) string {
ts, _ := time.Parse(time.RFC3339, item.Start.DateTime)
color := "white"
if ts.Before(time.Now()) {
color = "grey"
}
return color
}
func titleColor(item *calendar.Event) string { func titleColor(item *calendar.Event) string {
ts, _ := time.Parse(time.RFC3339, item.Start.DateTime) ts, _ := time.Parse(time.RFC3339, item.Start.DateTime)
@ -86,17 +110,6 @@ func titleColor(item *calendar.Event) string {
return color return color
} }
func descriptionColor(item *calendar.Event) string {
ts, _ := time.Parse(time.RFC3339, item.Start.DateTime)
color := "white"
if ts.Before(time.Now()) {
color = "grey"
}
return color
}
// until returns the number of hours or days until the event // until returns the number of hours or days until the event
// If the event is in the past, returns nil // If the event is in the past, returns nil
func (widget *Widget) until(start time.Time) string { func (widget *Widget) until(start time.Time) string {

View File

@ -35,7 +35,7 @@ func NewWidget() *Widget {
func (widget *Widget) Refresh() { func (widget *Widget) Refresh() {
data := Fetch() data := Fetch()
widget.View.SetTitle(" πŸ¦‚ Security ") widget.View.SetTitle(" 🀺 Security ")
widget.RefreshedAt = time.Now() widget.RefreshedAt = time.Now()
widget.View.Clear() widget.View.Clear()

View File

@ -55,7 +55,7 @@ func (widget *Widget) addView() {
} }
func (widget *Widget) contentFrom() string { func (widget *Widget) contentFrom() string {
icons := []string{"πŸ‘", "🀜", "πŸ€™", "🀜"} icons := []string{"πŸ‘", "🀜", "πŸ€™", "🀜", "🀘", "🀜", "✊", "🀜", "πŸ‘Œ", "🀜"}
next := icons[widget.Current] next := icons[widget.Current]
widget.Current = widget.Current + 1 widget.Current = widget.Current + 1