alert at end of event too

main
Bel LaPointe 2025-02-24 12:30:46 -07:00
parent f1846ed93c
commit aeb575e621
3 changed files with 29 additions and 4 deletions

16
gcal.go
View File

@ -24,8 +24,9 @@ func NewGCal() *GCal {
}
type Event struct {
Name string
Time time.Time
Name string
Time time.Time
Duration time.Duration
}
func (gcal *GCal) EventsToday(ctx context.Context) ([]Event, error) {
@ -60,9 +61,16 @@ func (gcal *GCal) EventsToday(ctx context.Context) ([]Event, error) {
} else if t.After(tomorrow) {
continue
}
var d time.Duration
if t2, err := time.Parse(time.RFC3339, events.Items[i].End.DateTime); err == nil {
d = t2.Sub(t)
}
result = append(result, Event{
Name: events.Items[i].Summary,
Time: t,
Name: events.Items[i].Summary,
Time: t,
Duration: d,
})
}
return result, nil

View File

@ -13,4 +13,13 @@ func TestGCal(t *testing.T) {
if err := gcal.Login(context.Background()); err != nil {
t.Fatal(err)
}
today, err := gcal.EventsToday(context.Background())
if err != nil {
t.Fatal(err)
} else {
for i := range today {
t.Logf("[%d] %+v", i, today[i])
}
}
}

View File

@ -104,6 +104,14 @@ func alertsGCal(ctx context.Context) (chan string, error) {
select {
case <-ctx.Done():
case ch <- events[0].Name:
select {
case <-ctx.Done():
case <-time.After(events[0].Duration):
select {
case <-ctx.Done():
case ch <- "/" + events[0].Name:
}
}
}
events = events[1:]
case <-ctx.Done():