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 {
str := "\n"
for _, item := range events.Items {
startTime, _ := time.Parse(time.RFC3339, item.Start.DateTime)
for _, event := range events.Items {
startTime, _ := time.Parse(time.RFC3339, event.Start.DateTime)
timestamp := startTime.Format("Mon, Jan 2, 15:04")
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
}
// 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 {
ts, _ := time.Parse(time.RFC3339, item.Start.DateTime)
@@ -86,17 +110,6 @@ func titleColor(item *calendar.Event) string {
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
// If the event is in the past, returns nil
func (widget *Widget) until(start time.Time) string {