Skip to content

Instantly share code, notes, and snippets.

@slakat
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save slakat/3556e457192264c80b21 to your computer and use it in GitHub Desktop.

Select an option

Save slakat/3556e457192264c80b21 to your computer and use it in GitHub Desktop.
Find all the dates for a weekday in a date range
WEEK={"Lunes"=> 1,"Martes" => 2, "Miércoles" => 3, "Jueves" => 4, "Viernes" => 5}
def repeating_events(day)
start_date = self.start_time.to_date # your start
end_date = self.end_time.to_date # your end
my_days = [WEEK[day]] # day of the week in 0-6. Sunday is day-of-week 0; Saturday is day-of-week 6.
return (start_date..end_date).to_a.select {|k| my_days.include?(k.wday)}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment