Last active
August 29, 2015 14:16
-
-
Save slakat/3556e457192264c80b21 to your computer and use it in GitHub Desktop.
Find all the dates for a weekday in a date range
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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