mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Mark calendar start time conflicts
This commit is contained in:
parent
bd078f0a0e
commit
04c3effcea
@ -58,6 +58,11 @@ func Fetch() (*calendar.Events, error) {
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
|
||||
func fromMidnight() time.Time {
|
||||
now := time.Now()
|
||||
return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
}
|
||||
|
||||
// getClient uses a Context and Config to retrieve a Token
|
||||
// then generate a Client. It returns the generated Client.
|
||||
func getClient(ctx context.Context, config *oauth2.Config) *http.Client {
|
||||
@ -92,11 +97,6 @@ func getTokenFromWeb(config *oauth2.Config) *oauth2.Token {
|
||||
return tok
|
||||
}
|
||||
|
||||
func fromMidnight() time.Time {
|
||||
now := time.Now()
|
||||
return time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
}
|
||||
|
||||
// tokenCacheFile generates credential file path/filename.
|
||||
// It returns the generated credential path/filename.
|
||||
func tokenCacheFile() (string, error) {
|
||||
|
@ -67,11 +67,13 @@ func (widget *Widget) contentFrom(events *calendar.Events) string {
|
||||
|
||||
str := ""
|
||||
for _, event := range events.Items {
|
||||
conflict := widget.hasConflict(event, events)
|
||||
|
||||
str = str + fmt.Sprintf(
|
||||
"%s [%s]%s[white]\n [%s]%s %s[white]\n\n",
|
||||
widget.dayDivider(event, prevEvent),
|
||||
widget.titleColor(event),
|
||||
widget.eventSummary(event),
|
||||
widget.eventSummary(event, conflict),
|
||||
widget.descriptionColor(event),
|
||||
widget.eventTimestamp(event),
|
||||
widget.until(event),
|
||||
@ -96,12 +98,33 @@ func (widget *Widget) dayDivider(event, prevEvent *calendar.Event) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (widget *Widget) eventSummary(event *calendar.Event) string {
|
||||
if widget.eventIsNow(event) {
|
||||
return fmt.Sprintf("%s %s", Config.UString("wtf.mods.gcal.currentIcon", "🔸"), event.Summary)
|
||||
func (widget *Widget) descriptionColor(event *calendar.Event) string {
|
||||
ts, _ := time.Parse(time.RFC3339, event.Start.DateTime)
|
||||
|
||||
color := "white"
|
||||
if (widget.eventIsNow(event) == false) && ts.Before(time.Now()) {
|
||||
color = "grey"
|
||||
}
|
||||
|
||||
return color
|
||||
}
|
||||
|
||||
func (widget *Widget) eventSummary(event *calendar.Event, conflict bool) string {
|
||||
summary := event.Summary
|
||||
|
||||
if widget.eventIsNow(event) {
|
||||
summary = fmt.Sprintf(
|
||||
"%s %s",
|
||||
Config.UString("wtf.mods.gcal.currentIcon", "🔸"),
|
||||
event.Summary,
|
||||
)
|
||||
}
|
||||
|
||||
if conflict {
|
||||
return fmt.Sprintf("%s %s", Config.UString("wtf.mods.gcal.conflictIcon", "🚨"), summary)
|
||||
} else {
|
||||
return event.Summary
|
||||
}
|
||||
}
|
||||
|
||||
func (widget *Widget) eventTimestamp(event *calendar.Event) string {
|
||||
@ -117,15 +140,23 @@ func (widget *Widget) eventIsNow(event *calendar.Event) bool {
|
||||
return time.Now().After(startTime) && time.Now().Before(endTime)
|
||||
}
|
||||
|
||||
func (widget *Widget) descriptionColor(event *calendar.Event) string {
|
||||
ts, _ := time.Parse(time.RFC3339, event.Start.DateTime)
|
||||
// hasConflict returns TRUE if this event conflicts with another, FALSE if it does not
|
||||
// Very basic implementation. Should really operate on ranges
|
||||
func (widget *Widget) hasConflict(event *calendar.Event, events *calendar.Events) bool {
|
||||
conflict := false
|
||||
|
||||
color := "white"
|
||||
if (widget.eventIsNow(event) == false) && ts.Before(time.Now()) {
|
||||
color = "grey"
|
||||
for _, otherEvent := range events.Items {
|
||||
if event == otherEvent {
|
||||
continue
|
||||
}
|
||||
|
||||
return color
|
||||
if event.Start.DateTime == otherEvent.Start.DateTime {
|
||||
conflict = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return conflict
|
||||
}
|
||||
|
||||
func (widget *Widget) titleColor(event *calendar.Event) string {
|
||||
|
Loading…
x
Reference in New Issue
Block a user