gal/struct_calendar.go
Brian Buller 23b8a190ec Colorize some results
* Can toggle default calendars
  * Though the interactive screen doesn't update :(
* Colorize default view depending on time until event
2017-03-02 10:26:34 -06:00

128 lines
3.4 KiB
Go

package main
import (
"time"
calendar "google.golang.org/api/calendar/v3"
)
type Calendar struct {
AccessRole string
BackgroundColor string
ColorId string
DefaultReminders []*calendar.EventReminder // TODO: Local Reminder struct?
Deleted bool
Description string
Etag string
ForegroundColor string
Hidden bool
Id string
Kind string
Location string
NotificationSettings *calendar.CalendarListEntryNotificationSettings // TODO: Needed?
Primary bool
Selected bool
Summary string
SummaryOverride string
TimeZone string
ForceSendFields []string // TODO: Needed?
NullFields []string //TODO: Needed?
}
func GoogleCalendarToLocal(c *calendar.CalendarListEntry) *Calendar {
ret := Calendar{
AccessRole: c.AccessRole,
BackgroundColor: c.BackgroundColor,
ColorId: c.ColorId,
DefaultReminders: c.DefaultReminders,
Deleted: c.Deleted,
Description: c.Description,
Etag: c.Etag,
ForegroundColor: c.ForegroundColor,
Hidden: c.Hidden,
Id: c.Id,
Kind: c.Kind,
Location: c.Location,
Primary: c.Primary,
Selected: c.Selected,
Summary: c.Summary,
SummaryOverride: c.SummaryOverride,
TimeZone: c.TimeZone,
}
return &ret
}
func (c *Calendar) GetTodaysEvents() []Event {
var ret []Event
minTime := time.Date(
time.Now().Year(),
time.Now().Month(),
time.Now().Day(),
0, 0, 0, 0, time.Local,
)
maxTime := time.Date(
time.Now().Year(),
time.Now().Month(),
time.Now().Day(),
23, 59, 59, 999999999, time.Local,
)
events, err := state.account.Service.Events.List(c.Id).
ShowDeleted(false).
SingleEvents(true).
TimeMin(minTime.Format(time.RFC3339)).
TimeMax(maxTime.Format(time.RFC3339)).
OrderBy("startTime").
Do()
if err != nil {
return ret
}
for _, e := range events.Items {
ret = append(ret, *GoogleEventToLocal(e))
}
return ret
}
func (c *Calendar) GetCalendarEvents() []Event {
var ret []Event
events, err := state.account.Service.Events.List(c.Id).ShowDeleted(false).
SingleEvents(true).OrderBy("startTime").Do()
if err != nil {
return ret
}
for _, e := range events.Items {
ret = append(ret, *GoogleEventToLocal(e))
}
return ret
}
/* For Adding a private copy of an existing event
func (c *Calendar) ImportEvent(event *Event) error {
_, err := state.account.Service.Events.Import(c.Id, event).Do()
return err
}
*/
func (c *Calendar) InsertEvent(event *Event) (*Event, error) {
e, err := state.account.Service.Events.Insert(c.Id, LocalEventToGoogle(event)).Do()
return GoogleEventToLocal(e), err
}
func (c *Calendar) DeleteEvent(eId string) error {
return state.account.Service.Events.Delete(c.Id, eId).Do()
}
func (c *Calendar) GetEvent(eId string) (*Event, error) {
e, err := state.account.Service.Events.Get(c.Id, eId).Do()
return GoogleEventToLocal(e), err
}
func (c *Calendar) QuickAdd(text string) (*Event, error) {
e, err := state.account.Service.Events.QuickAdd(c.Id, text).Do()
return GoogleEventToLocal(e), err
}
func (c *Calendar) Update(eId string, event *Event) (*Event, error) {
e, err := state.account.Service.Events.Update(c.Id, eId, LocalEventToGoogle(event)).Do()
return GoogleEventToLocal(e), err
}