The Movie Database 支持

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...",

2 回复(第 1 页,共 1 页)

Jump to last post

@the-physicist said:
Algorithm to return decades and not specific years
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?`

If I choose 70s, the API returns "year": "1970", and it should return "year": "1970, 1971, 1972...",

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

https://api.themoviedb.org/3/discover/movie?language=en&page=1&primary_release_date.gte=1970-01-01&primary_release_date.lte=1979-12-31&sort_by=primary_release_date.asc

And use the filter &sort_by=primary_release_date.asc.

Thank you, it worked!!

找不到电影或节目?登录并创建它吧。

全站通用

s 聚焦到搜索栏
p 打开个人资料菜单
esc 关闭打开的窗口
? 打开键盘快捷键窗口

在媒体页面

b 返回(或返回上级)
e 进入编辑页面

在电视季页面

(右箭头)下一季
(左箭头)前一季

在电视集页面

(右箭头)下一集
(左箭头)上一集

在所有图像页面

a 打开添加图片窗口

在所有编辑页面

t 打开翻译选择器
ctrl+ s 提交

在讨论页面

n 创建新讨论
w 切换关注状态
p 设为公开 / 私密讨论
c 关闭 / 开放讨论
a 打开活动页
r 回复讨论
l 跳转至最新回复
ctrl+ enter 发送信息
(右箭头)下一页
(左箭头)前一页

设置

想给这个条目评分或将其添加到片单中?

登录

还不是会员?

注册加入社区