Last active
August 29, 2015 13:58
-
-
Save richardking/9979324 to your computer and use it in GitHub Desktop.
15422 next previous game date
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
| def previous_game_date | |
| @previous_game_date ||= if Score.cached_previous_league_game(@params[:league], @params[:sport], @tz, @date) | |
| Time.parse(Score.cached_previous_league_game(@params[:league], @params[:sport], @tz, @date)["startTime"]).in_time_zone(@tz) | |
| elsif GameFinder.new.previous_game_before_date(@params[:league], @params[:sport], @tz, @date) | |
| GameFinder.new.previous_game_before_date(@params[:league], @params[:sport], @tz, @date)["starts_at"].in_time_zone(@tz) | |
| else | |
| @date-1.day | |
| end | |
| end | |
| def next_game_date | |
| @next_game_date ||= if Score.cached_next_league_game(@params[:league], @params[:sport], @tz, @date) | |
| Time.parse(Score.cached_next_league_game(@params[:league], @params[:sport], @tz, @date)["startTime"]).in_time_zone(@tz) | |
| elsif GameFinder.new.next_game_after_date(@params[:league], @params[:sport], @tz, @date) | |
| GameFinder.new.next_game_after_date(@params[:league], @params[:sport], @tz, @date)["starts_at"].in_time_zone(@tz) | |
| else | |
| @date+1.day | |
| end | |
| end | |
| def next_game_after_date(competition, sport, tz, date=Time.now) | |
| self.starts_after(date.in_time_zone(tz).end_of_day).league(competition, sport).order('starts_at asc').first | |
| end | |
| def previous_game_before_date(competition, sport, tz, date=Time.now) | |
| self.starts_before(date.in_time_zone(tz).beginning_of_day).league(competition, sport).order('starts_at desc').first | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment