Documentation ¶
Overview ¶
Package meetingtime provides tools for calculating dates and times for regularly occurring meetings.
Index ¶
Examples ¶
Constants ¶
const ErrNoEarlierMeetings = errorStr("no meetings on or before this date")
ErrNoEarlierMeetings indicates that Previous was called with a date before the first meeting of a Schedule
Variables ¶
This section is empty.
Functions ¶
func GetWeekdayAndIndex ¶
GetWeekdayAndIndex returns the Weekday of a given time, along with the count of that particular day in the month. For example: a time on October 12th 2016, would return Wednesday and 2, since that date is the second Wednesday in the month.
Types ¶
type Schedule ¶
type Schedule struct { Type ScheduleType // Type of recurrence First time.Time // Time and date of first meeting Frequency uint // How frequently this meeting occurs. For a daily meeting, 2 would mean every other day. }
Schedule defines a regular schedule for a meeting
Example ¶
// Create a Schedule for a meeting that occurs every other month on the 10th at 6pm schedule := NewMonthlySchedule(time.Date(2016, time.January, 10, 18, 0, 0, 0, time.UTC), 2) // Get the second meeting by asking for the next meeting from 1 minute after the first secondMeeting, err := schedule.Next(time.Date(2016, time.January, 10, 18, 1, 0, 0, time.UTC)) if err != nil { fmt.Println(err) return } fmt.Println(secondMeeting.Format(time.UnixDate)) // Get the first meeting by asking for the meeting previous to the second first, err := schedule.Previous(secondMeeting) if err != nil { fmt.Println(err) return } fmt.Println(first.Format(time.UnixDate)) // Create a Schedule for a daily meeting at 2.30pm schedule = NewDailySchedule(time.Date(2016, time.February, 1, 14, 30, 0, 0, time.UTC), 1) // An ErrNoEarlierMeetings error is returned if you try to get the meeting before the first _, err = schedule.Previous(time.Date(2016, time.February, 1, 14, 30, 0, 0, time.UTC)) if err != nil { fmt.Println(err) } // An ErrNoEarlierMeetings error is also returned for calling previous on any earlier date _, err = schedule.Previous(time.Date(2016, time.January, 31, 0, 0, 0, 0, time.UTC)) if err != nil { fmt.Println(err) }
Output: Thu Mar 10 18:00:00 UTC 2016 Sun Jan 10 18:00:00 UTC 2016 no meetings on or before this date no meetings on or before this date
func NewDailySchedule ¶
NewDailySchedule creates a schedule recurring every n days
func NewMonthlySchedule ¶
NewMonthlySchedule creates a schedule recurring on the specified day in the month, every n months.
func NewMonthlyScheduleByWeekday ¶
NewMonthlyScheduleByWeekday creates a schedule recurring every month on the same day of the week as the first meeting (for example, the 2nd Wednesday).
func NewWeeklySchedule ¶
NewWeeklySchedule creates a schedule recurring on the same day every n weeks
func NewYearlySchedule ¶
NewYearlySchedule creates a schedule recurring every n years
type ScheduleSlice ¶
type ScheduleSlice []Schedule
ScheduleSlice allows Schedule instances to be grouped to create more complex schedules.
Example ¶
// Create a ScheduleSlice for a meeting on the 1st and 3rd Monday of each month at 7pm schedule := ScheduleSlice{ NewMonthlyScheduleByWeekday(time.Date(2016, time.September, 5, 19, 0, 0, 0, time.UTC)), NewMonthlyScheduleByWeekday(time.Date(2016, time.September, 19, 19, 0, 0, 0, time.UTC)), } // Get the first meeting in October firstInOct, err := schedule.Next(time.Date(2016, time.October, 1, 0, 0, 0, 0, time.UTC)) if err != nil { fmt.Println(err) return } fmt.Println(firstInOct.Format(time.UnixDate)) // Get the next meeting after this secondInOct, err := schedule.Next(firstInOct) if err != nil { fmt.Println(err) return } fmt.Println(secondInOct.Format(time.UnixDate))
Output: Mon Oct 3 19:00:00 UTC 2016 Mon Oct 17 19:00:00 UTC 2016
type ScheduleType ¶
type ScheduleType uint8
ScheduleType specifies the way in which this schedule recurs
const ( // Daily specifies a meeting that recurs daily. Daily ScheduleType = iota // Weekly specifies a meeting that recurs weekly. Weekly // Monthly specifies a meeting that recurs monthly. Monthly // MonthlyByWeekday specifies a meeting that recurs on the nth weekday of the month (2nd Wednesday, for example), based on the first meeting date. MonthlyByWeekday // Yearly specifes a meeting that recurs yearly. Yearly )