64 lines
1.0 KiB
Go
64 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"google.golang.org/api/calendar/v3"
|
|
)
|
|
|
|
type Class struct {
|
|
Summary string
|
|
Start string
|
|
End string
|
|
Students []string
|
|
Days []time.Weekday
|
|
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) 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
|
|
}
|