// Package meetup is for meetup date handling.
package meetup
import (
"time"
)
// WeekSchedule represents a schedulding type.
type WeekSchedule int
const (
// First in the month
First WeekSchedule = iota
// Second in the month
Second
// Third in the month
Third
// Fourth int the month
Fourth
// Last in the month
Last
// Teenth in the month (monteenth, tuesteenth...)
Teenth
)
// Day returns the meeting day based on input.
func Day(ws WeekSchedule, day time.Weekday, month time.Month, year int) int {
var occurance int
for t := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC); ; t = t.AddDate(0, 0, 1) {
if t.Weekday() == day {
if ws == Teenth && t.Day() > 12 {
return t.Day()
}
if ws == Last {
if t.AddDate(0, 0, 7).Month() != t.Month() {
return t.Day()
}
}
if int(ws) == occurance {
return t.Day()
}
occurance++
}
}
}