Skip to content

Instantly share code, notes, and snippets.

@biggianteye
Created July 25, 2023 15:07
Show Gist options
  • Save biggianteye/d84fe15ca10d2b15c0ca961b62e381aa to your computer and use it in GitHub Desktop.
Save biggianteye/d84fe15ca10d2b15c0ca961b62e381aa to your computer and use it in GitHub Desktop.
A script to work out the dates of codebar workshops for the West London chapter
package main
// A script to work out the dates of codebar workshops for the West London chapter.
// Our workshops are on the second and fourth Tuesdays of every month.
// https://codebar.io/west-london
import "time"
import "fmt"
func main() {
// What year?
const year = 2024
// Only for the required year
lowerDate := time.Date(year, 1, 1, 0, 0, 0, 0, time.UTC)
upperDate := time.Date(year+1, 1, 1, 0, 0, 0, 0, time.UTC)
currentDate := lowerDate
// Grab all the Tuesdays in the year
tuesdaysByMonth := make(map[time.Month][]time.Time)
for i := time.January; i <= time.December; i++ {
tuesdaysByMonth[i] = make([]time.Time, 0)
}
for currentDate.Before(upperDate) {
if currentDate.Weekday() == time.Tuesday {
month := currentDate.Month()
tuesdaysByMonth[month] = append(tuesdaysByMonth[month], currentDate)
}
currentDate = currentDate.Add(24 * time.Hour)
}
// Pull out the second and fourth Tuesdays
workshopDays := make([]time.Time, 0)
for i := time.January; i <= time.December; i++ {
workshopDays = append(workshopDays, tuesdaysByMonth[i][1], tuesdaysByMonth[i][3])
}
for _, day := range workshopDays {
fmt.Printf("%s\n", day.Format("02/01/2006"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment