Files
helioscal/class.go
2020-09-13 21:27:40 +00:00

79 lines
1.3 KiB
Go

package main
import (
"fmt"
"log"
"time"
"google.golang.org/api/calendar/v3"
)
type Class struct {
Summary string
Start string
End string
Students []string
Days []time.Weekday
Tags map[string]string
Zoom string
}
func (c Class) happensOnDay(t time.Time) bool {
for _, day := range c.Days {
if day == t.Weekday() {
return true
}
}
return false
}
func (c Class) tagsMatch(t time.Time) bool {
for key, value := range c.Tags {
tagValue, err := getTagAt(key, t)
if err != nil {
log.Fatal(err)
}
if value != tagValue {
return false
}
}
return true
}
func (c Class) buildEvent(t time.Time) *calendar.Event {
dateStr := t.Format("2006-01-02")
ev := &calendar.Event{
Summary: c.Summary,
Start: &calendar.EventDateTime{
DateTime: fmt.Sprintf("%sT%s:00", dateStr, c.Start),
TimeZone: "US/Pacific",
},
End: &calendar.EventDateTime{
DateTime: fmt.Sprintf("%sT%s:00", dateStr, c.End),
TimeZone: "US/Pacific",
},
Attendees: []*calendar.EventAttendee{},
}
attendees := c.Students
if len(attendees) == 0 {
attendees = allStudents
}
for _, student := range attendees {
ev.Attendees = append(
ev.Attendees,
&calendar.EventAttendee{
Email: student,
},
)
}
if c.Zoom != "" {
ev.Description = fmt.Sprintf(`Zoom: %s`, c.Zoom)
}
return ev
}