meetingtime

package module
v0.0.0-...-1ce716a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2017 License: MIT Imports: 2 Imported by: 0

README

meetingtime

Build Status GoDoc Go Report Card Coverage Status

Package meetingtime provides tools for calculating dates and times for regularly occurring meetings.

Basic Usage

Start by defining a Schedule:

// Create a Schedule for a meeting that occurs every other month on the 10th at 6pm
schedule := meetingtime.NewMonthlySchedule(time.Date(2016, time.January, 10, 18, 0, 0, 0, time.UTC), 2)

Then query the Schedule to obtain the date of the next meeting as a time.Time value:

// Get the next meeting after the current time
nextMeeting, err := schedule.Next(time.Now())

Schedule Types

meetingtime provides a variety of schedule types:

  • Daily
  • Weekly
  • Monthly
  • Monthly by Weekday
  • Yearly

Daily, Weekly, Monthly and Yearly schedules accept a frequency value, to allow for schedules such as "every other Monday". The Monthly by Weekday type permits schedules like "the second Tuesday of each month", this type does not take a frequency, and any frequency value will be ignored.

Complex schedules

More complicated schedules can be represented by combinations of Schedule values using the ScheduleSlice type.

// 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))

Describing a Schedule

The describe package provides a function (describe.Schedule) for creating English descriptions for meetingtime.Schedule values.

See the describe godoc for more details.

describe does not currently have i18n support.

Having Trouble?

If you're having trouble with meetingtime, please raise a GitHub issue and we'll do what we can to help, or make fixes as needed.

Contributing

Contributions are always more than welcome, feel free to pick up an issue and/or send a PR. Alternatively, just raise an issue with your idea for improvements.

License

meetingtime is provided under the MIT License.

Documentation

Overview

Package meetingtime provides tools for calculating dates and times for regularly occurring meetings.

Index

Examples

Constants

View Source
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

func GetWeekdayAndIndex(t time.Time) (weekday time.Weekday, n int)

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

func NewDailySchedule(first time.Time, n uint) Schedule

NewDailySchedule creates a schedule recurring every n days

func NewMonthlySchedule

func NewMonthlySchedule(first time.Time, n uint) Schedule

NewMonthlySchedule creates a schedule recurring on the specified day in the month, every n months.

func NewMonthlyScheduleByWeekday

func NewMonthlyScheduleByWeekday(first time.Time) Schedule

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

func NewWeeklySchedule(first time.Time, n uint) Schedule

NewWeeklySchedule creates a schedule recurring on the same day every n weeks

func NewYearlySchedule

func NewYearlySchedule(first time.Time, n uint) Schedule

NewYearlySchedule creates a schedule recurring every n years

func (Schedule) Next

func (s Schedule) Next(t time.Time) (time.Time, error)

Next returns the time of the next meeting after the given time.

func (Schedule) Previous

func (s Schedule) Previous(t time.Time) (time.Time, error)

Previous returns the time of the closest meeting before the given time.

If the given time is before the first meeting, ErrNoEarlierMeetings will be returned.

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

func (ScheduleSlice) Next

func (schedules ScheduleSlice) Next(t time.Time) (time.Time, error)

Next returns the earliest next meeting from all Schedules in the slice.

func (ScheduleSlice) Previous

func (schedules ScheduleSlice) Previous(t time.Time) (time.Time, error)

Previous returns the latest previous from all Schedules in the slice.

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
)

Directories

Path Synopsis
Package describe provides tools to generate English descriptions of Schedules from the meetingtime package.
Package describe provides tools to generate English descriptions of Schedules from the meetingtime package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL