Пример #1
0
 public static function by_date($timestamp)
 {
     if (!is_numeric($timestamp)) {
         throw new InvalidArgumentException("Season::by_date expects a timestamp as parameter");
     }
     $seasons = Season::all();
     $seasons = array_filter($seasons, function ($season) use($timestamp) {
         $start = strtotime(get_post($season->first_episode()->post_id)->post_date);
         $end = strtotime(get_post($season->last_episode()->post_id)->post_date);
         return $start <= $timestamp && ($end >= $timestamp || $season->is_running());
     });
     if (count($seasons) > 0) {
         return reset($seasons);
     } else {
         return null;
     }
 }