Skip to content

Instantly share code, notes, and snippets.

@sihu
Created December 21, 2020 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sihu/015de3c10594cf1d120af2837c2e0926 to your computer and use it in GitHub Desktop.
Save sihu/015de3c10594cf1d120af2837c2e0926 to your computer and use it in GitHub Desktop.
Laundry Day Generator
require 'date'
require 'icalendar'
# Washday-ICS Generator
# /////////////////////////
# Author: Simon Huber
# Description: This script generates an ics file with a series of laundry_days.
# We are 5 parties and there are always 2 consecutive days, but not Sunday.
year = 2021
first_laundry_day_of_year = Date.new(year, 1, 8)
current_date = first_laundry_day_of_year
events = []
while current_date.year == year
events.push(current_date)
current_date += current_date.wday > 2 ? 12 : 11
end
cal = Icalendar::Calendar.new
events.each do |date|
event = Icalendar::Event.new
event.dtstart = Icalendar::Values::Date.new(date)
event.dtend = Icalendar::Values::Date.new(date + 2)
event.summary = 'Laundry day'
event.transp = 'TRANSPARENT'
cal.add_event(event)
end
File.open('laundry_days.ics', 'w') { |file| file.write(cal.to_ical) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment