update recentMovies to filter by current week
This commit is contained in:
parent
ab3618a632
commit
6f7c9d149b
2 changed files with 6 additions and 4 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
<section *ngIf="movies.length > 0" class="hide-scrollbar">
|
<section *ngIf="movies.length > 0" class="hide-scrollbar">
|
||||||
<!-- Column for films of the last 7 days -->
|
<!-- New movies this week (starts on Mondays) -->
|
||||||
<div *ngIf="recentMovies().length > 0" class="category">
|
<div *ngIf="recentMovies().length > 0" class="category">
|
||||||
<p>Added in the last 7 days</p>
|
<p>Added in the last 7 days</p>
|
||||||
<div class="movies">
|
<div class="movies">
|
||||||
|
|
|
||||||
|
|
@ -60,12 +60,14 @@ export class CategoriesComponent implements AfterViewInit {
|
||||||
|
|
||||||
recentMovies() {
|
recentMovies() {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const sevenDaysAgo = new Date(today);
|
const dayOfWeek = today.getDay();
|
||||||
sevenDaysAgo.setDate(today.getDate() - 7);
|
|
||||||
|
const lastMonday = new Date(today);
|
||||||
|
lastMonday.setDate(today.getDate() - ((dayOfWeek + 6) % 7));
|
||||||
|
|
||||||
return this.movies.filter((movie) => {
|
return this.movies.filter((movie) => {
|
||||||
const movieDate = new Date(movie.created_at);
|
const movieDate = new Date(movie.created_at);
|
||||||
return movieDate >= sevenDaysAgo;
|
return movieDate >= lastMonday && movieDate <= today;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue