Documentation
¶
Index ¶
- Constants
- func CalculateReminderTimes(startsAt time.Time, durations []time.Duration) []time.Time
- func CompareEvent(a, b Event) int
- func CompareTime(a, b time.Time) int
- func ReminderTimes(reminders []Reminder) []time.Time
- type Calendar
- type Event
- type EventStatus
- type EventsOpts
- type ICSCalendar
- type Notification
- type Notifier
- type NotifierOpts
- type NotifierState
- type OnlineICSCalendar
- type Reminder
- type ReminderAction
- type ReminderParseFunc
Constants ¶
const Day = 24 * time.Hour
Day is a day duration.
Variables ¶
This section is empty.
Functions ¶
func CalculateReminderTimes ¶
CalculateReminderTimes calculates reminder times for the given startsAt timestamp. Note that all durations are subtracted from the startsAt time.
func CompareEvent ¶
CompareEvent compares two events by start time.
func ReminderTimes ¶
ReminderTimes returns a list of trigger times for the given reminders.
Types ¶
type Calendar ¶
type Calendar interface {
// EventsBetween returns events between start and end. The returned events
// are sorted by start time. If includeReminders is true, then it will also
// search for events that have reminders that fall within the time range.
EventsBetween(start, end time.Time, opts EventsOpts) []Event
}
Calendar describes a generic calendar. For a specific implementation, see ICSCalendar.
type Event ¶
type Event struct {
StartsAt time.Time
EndsAt time.Time
Summary string // title
Location string
Description string
Status EventStatus
Reminders []Reminder
}
Event is a calendar event.
func EventsWithin ¶
EventsWithin returns events that are happening within the given duration from the given time.
type EventStatus ¶
type EventStatus = ical.EventStatus
EventStatus is an event status.
const ( EventStatusUnknown EventStatus = "" EventTentative EventStatus = ical.EventTentative EventConfirmed EventStatus = ical.EventConfirmed EventCancelled EventStatus = ical.EventCancelled )
type EventsOpts ¶
type EventsOpts struct {
// ParseReminder, if not nil, is called for every event to extract reminders
// from it.
ParseReminder ReminderParseFunc
// DefaultReminders is a list of default reminders to add to all events.
// Durations in this list are subtracted from the event's start time.
DefaultReminders []time.Duration
// DefaultReminderAction is the default reminder action to use for all
// default reminders. If empty, the action will be set to DISPLAY.
DefaultReminderAction ReminderAction
// IncludeReminders will also search for events that have reminders that
// fall within the time range.
IncludeReminders bool
// ExcludeCancelled will exclude cancelled events.
ExcludeCancelled bool
}
EventsOpts are options for EventsBetween.
func (EventsOpts) EventReminders ¶
func (o EventsOpts) EventReminders(e Event) []Reminder
EventReminders returns a list of reminders for the given event. It is a helper function that collects reminders from the reminder parser and the default reminders.
type ICSCalendar ¶
type ICSCalendar struct {
// contains filtered or unexported fields
}
ICSCalendar represents a calendar. An ICSCalendar is immutable: once created, it cannot be modified. It is safe to use from multiple goroutines.
func NewICS ¶
func NewICS(ical *ical.Calendar) *ICSCalendar
NewICS creates a new calendar from an ICS calendar.
func ParseICS ¶
func ParseICS(r io.Reader) (*ICSCalendar, error)
ParseICS parses an ICS-formatted calendar from r.
func (*ICSCalendar) Equals ¶
func (c *ICSCalendar) Equals(x *ICSCalendar) bool
Equals compares two calendars.
func (*ICSCalendar) EventsBetween ¶
func (c *ICSCalendar) EventsBetween(start, end time.Time, opts EventsOpts) []Event
EventsBetween implements Calendar.EventsBetween.
type Notification ¶
type Notification struct {
// Calendar is the calendar that the event belongs to.
Calendar Calendar
// Event is the event that is about to happen.
Event Event
// RemindedAt is the time that the notification was sent.
RemindedAt time.Time
}
Notification is a calendar notification.
func (Notification) IsZero ¶
func (n Notification) IsZero() bool
IsZero returns true if the notification is zero.
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier contains controls for a Monitor.
func NewNotifier ¶
func NewNotifier(opts NotifierOpts) *Notifier
NewNotifier creates a new notifier.
func (*Notifier) Invalidate ¶
func (n *Notifier) Invalidate()
Invalidate invalidates the notifier's state. It calls Update with a no-op function. Use this if you want to force the notifier to recompute its state when any of the calendars have changed.
func (*Notifier) Notify ¶
func (n *Notifier) Notify(ctx context.Context, dst chan<- Notification) error
Notify starts the notifier. It returns when the context is done. It may drop notifications if the channel is not ready to receive them in time.
func (*Notifier) Update ¶
func (n *Notifier) Update(fn func(*NotifierState))
Update updates the notifier's state. It runs fn synchronously, so it will block until the update is complete. It is safe to call Update from multiple goroutines.
type NotifierOpts ¶
type NotifierOpts struct {
EventsOpts
// Location is the location of the calendar events. If nil, the
// system's local time is used.
Location *time.Location
// SkipPastNotifications, if true, will skip notifications that were
// supposed to be sent in the past for events that are still upcoming.
// This is useful as a recovery mechanism if the notifier was down for
// a while.
SkipPastNotifications bool
}
type NotifierState ¶
type NotifierState struct {
Calendars map[Calendar]struct{}
}
NotifierState is the state of a Notifier.
func (*NotifierState) AddCalendar ¶
func (n *NotifierState) AddCalendar(cal Calendar)
AddCalendar adds a calendar to the notifier's state.
func (*NotifierState) RemoveCalendar ¶
func (n *NotifierState) RemoveCalendar(cal Calendar)
RemoveCalendar removes a calendar from the notifier's state.
type OnlineICSCalendar ¶
type OnlineICSCalendar struct {
// ICalURL is the URL to the ICS file.
ICalURL string
// contains filtered or unexported fields
}
OnlineICSCalendar represents an online calendar. It is safe for concurrent use.
func NewOnlineICSCalendar ¶
func NewOnlineICSCalendar(icalURL string) *OnlineICSCalendar
NewOnlineICSCalendar creates a new online calendar tracking an ICS URL.
func (*OnlineICSCalendar) EventsBetween ¶
func (c *OnlineICSCalendar) EventsBetween(start, end time.Time, opts EventsOpts) []Event
EventsBetween implements Calendar.EventsBetween. If Update has not been called, it will return an empty slice.
func (*OnlineICSCalendar) Refresh ¶
func (c *OnlineICSCalendar) Refresh(ctx context.Context) (changed bool, err error)
Refresh attempts to refresh the calendar. It returns an error if the calendar could not be updated. It returns true if the refreshed calendar is different from the previous calendar.
Note that although this method is safe for concurrent use, it is not guaranteed that the calendar is not updated multiple times concurrently.
func (*OnlineICSCalendar) String ¶
func (c *OnlineICSCalendar) String() string
String implements fmt.Stringer.
type Reminder ¶
type Reminder struct {
Action ReminderAction
RemindAt time.Time
}
Reminder is a calendar event reminder.
func EarliestReminder ¶
EarliestReminder returns the earliest reminder from a list of reminders.
func NewReminders ¶
func NewReminders(times []time.Time, action ReminderAction) []Reminder
NewReminders creates a list of reminders from a list of times.
func NewRemindersFromDuration ¶
func NewRemindersFromDuration(startsAt time.Time, durations []time.Duration, action ReminderAction) []Reminder
NewRemindersFromDuration creates a list of reminders from a list of durations.
type ReminderAction ¶
type ReminderAction string
ReminderAction is a reminder action type. It is defined by the iCalendar specification.
const ( ReminderActionAudio ReminderAction = "AUDIO" ReminderActionDisplay ReminderAction = "DISPLAY" ReminderActionEmail ReminderAction = "EMAIL" )
type ReminderParseFunc ¶
ReminderParseFunc parses reminders from a given event. This exists because the iCalendar specification does not define a standard way to represent reminders. This function is called for every event to extract reminders from it.