From 337f3aa1ca89c63e7dcfd99702f1554bc66a0815 Mon Sep 17 00:00:00 2001 From: Trevor Vallender Date: Sun, 3 Mar 2024 20:38:27 +0000 Subject: [PATCH] Set recurring events If we know the birth year, recur from there. Otherwise, recur from the current year. --- lib/birthdaze.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/birthdaze.rb b/lib/birthdaze.rb index 5bf9624..8d6fa3a 100644 --- a/lib/birthdaze.rb +++ b/lib/birthdaze.rb @@ -59,26 +59,35 @@ class Birthdaze < Thor @calendar = Icalendar::Calendar.new birthdays.each do |birthday| @calendar.event do |event| - event.dtstart = Icalendar::Values::Date.new(start_date(birthday, Date.today.year)) - event.dtend = Icalendar::Values::Date.new(end_date(birthday, Date.today.year)) + event.dtstart = Icalendar::Values::Date.new(start_date(birthday)) + event.dtend = Icalendar::Values::Date.new(end_date(birthday)) event.summary = summary(birthday) + event.description = description(birthday) + event.rrule = "FREQ=YEARLY;" end end @calendar.publish end # Takes a birthday string, with or without a year, and returns a start date - def start_date(birthday, year) + def start_date(birthday) + year = birthday[:birth_year] || Date.today.year "#{year}#{birthday[:month]}#{birthday[:day]}" end - def end_date(birthday, year) - date = Date.parse(start_date(birthday, year)).next_day + def end_date(birthday) + date = Date.parse(start_date(birthday)).next_day date.strftime("%Y%m%d") end def summary(birthday) - return "🎂 #{birthday[:name]}’s birthday" + "🎂 #{birthday[:name]}’s birthday" + end + + def description(birthday) + return "" unless birthday[:birth_year] + + "#{birthday[:name]} was born in #{birthday[:birth_year]}" end def set_reminders