diff --git a/app/Repositories/DefaultAnimeRepository.php b/app/Repositories/DefaultAnimeRepository.php index 786d75b7..f2c64eb2 100644 --- a/app/Repositories/DefaultAnimeRepository.php +++ b/app/Repositories/DefaultAnimeRepository.php @@ -12,6 +12,7 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Carbon; use Laravel\Scout\Builder as ScoutBuilder; +use MongoDB\BSON\Javascript; /** * @implements Repository @@ -164,7 +165,23 @@ public function getItemsBySeason( // We want to include those shows which have started in previous season only (not before) and it's going // to continue in the current season. $finalFilter['$or'][] = [ - 'aired.from' => ['$lte' => $from->toAtomString()], + // note: this expression only works with mongodb version 5.0.0 or higher + '$expr' => [ + '$lte' => [ + [ + '$dateDiff' => [ + 'startDate' => [ + '$dateFromString' => [ + 'dateString' => '$aired.from' + ] + ], + 'endDate' => new Javascript('new Date("' . $from->toAtomString() . '")'), + 'unit' => 'month' + ] + ], + 3 // there are 3 months in a season, so anything that started in 3 months or less will be included + ] + ], 'aired.to' => null, 'episodes' => ['$gte' => 14], 'airing' => true