Skip to content

Commit

Permalink
adjusted the continuing anime filter 3
Browse files Browse the repository at this point in the history
  • Loading branch information
pushrbx committed Jun 20, 2024
1 parent 31c7790 commit f775fbc
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion app/Repositories/DefaultAnimeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Anime>
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f775fbc

Please sign in to comment.