I would like to create an algorithm that searches for **decades **and not specific years.
For example, the 80s should return movies released in 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988 and 1989, totaling 10 years.
I have written about three different algorithms and they never work, they always return a specific year in the API.
Is this an API limitation or my stupidity?
Some code I tried:
<optgroup label="Décadas">
{Array.from({ length: 10 }, (_, i) => {
const decade = Math.floor(new Date().getFullYear() / 10) * 10 - i * 10;
return (
<option key={`decade-${decade}`} value={`${decade}`}>
Década de {decade}
</option>
);
})}
</optgroup>
export function getDecadeRange(decade: string): { startYear: string; endYear: string } {
// Verificar se é um valor de década (30, 40, etc) ou um ano especÃfico (1977, 2022, etc)
// Décadas são representadas por 2 dÃgitos
if (decade.length === 2) {
const decadeNum = parseInt(decade, 10);
// Para décadas do século 20 (antes de 2000)
if (decadeNum < 20) { // Assumindo que décadas de 00-19 são do século 21
return {
startYear: `20${decade}`, // ex: 00 -> 2000
endYear: `20${decade}9` // ex: 00 -> 2009
};
} else {
return {
startYear: `19${decade}`, // ex: 90 -> 1990
endYear: `19${decade}9` // ex: 90 -> 1999
};
}
}
If I choose 70s, the API returns "year": "1970", and it should return "year": "1970, 1971, 1972...",
Can't find a movie or TV show? Login to create it.
Want to rate or add this item to a list?
Not a member?
Reply by ticao2 🇧🇷 pt-BR
on March 20, 2025 at 8:45 AM
Using Discover,
https://developer.themoviedb.org/reference/discover-movie
specify a date range using the filters
"primary_release_date.gte" and "primary_release_date.lte".
For example, the 1970s.
&primary_release_date.gte=1970-01-01
&primary_release_date.lte=1979-12-31
And use the filter &sort_by=primary_release_date.asc.
Reply by the-physicist
on March 20, 2025 at 8:16 PM
Thank you, it worked!!