angular - 过滤startDate和EndDate在所选月份和年份范围内的所有对象

时间:2022-07-01 18:53:51

I want to filter and get all the campaigns that are in range of the month and year that is being sent. For example, StartDate - 2/1/16 EndDate - 1/2/17 year - 2016 month - 4 I want this campaign to show on all the months from Feb' 2016 to Jan' 2017

我想过滤并获取正在发送的月份和年份范围内的所有广告系列。例如,StartDate - 2/1/16 EndDate - 1/2/17年 - 2016月 - 4我希望此活动能够在2016年2月至2017年1月的所有月份展示

app.filter('dateFilter', function () {
    return function (campaigns, year, month) {
        var filtered = [];
        if (!campaigns)
            return null;
        for (var i = 0; i < campaigns.length; i++) {
            var startDate = new Date(campaigns[i].startTime);
            var endDate = new Date(campaigns[i].endTime);

            if ( Validation )
                filtered.push(campaigns[i]);
        }
        return filtered;
    };
});

1 个解决方案

#1


0  

Ok found the answer, it was pretty easy after all. I just created the startDate and endDate with an empty day value and checked the range.

好的找到答案,毕竟这很容易。我刚刚用空日值创建了startDate和endDate并检查了范围。

 for (var i = 0; i < campaigns.length; i++) {
            var startDate = new Date(campaigns[i].startTime);
            var endDate = new Date(campaigns[i].endTime);
            startDate = new Date(startDate.getFullYear(), startDate.getMonth());
            endDate = new Date(endDate.getFullYear(), endDate.getMonth());
            var dateCheck = new Date(year, month - 1);
            if (dateCheck >= startDate && dateCheck <= endDate)
                filtered.push(campaigns[i]);
        }

#1


0  

Ok found the answer, it was pretty easy after all. I just created the startDate and endDate with an empty day value and checked the range.

好的找到答案,毕竟这很容易。我刚刚用空日值创建了startDate和endDate并检查了范围。

 for (var i = 0; i < campaigns.length; i++) {
            var startDate = new Date(campaigns[i].startTime);
            var endDate = new Date(campaigns[i].endTime);
            startDate = new Date(startDate.getFullYear(), startDate.getMonth());
            endDate = new Date(endDate.getFullYear(), endDate.getMonth());
            var dateCheck = new Date(year, month - 1);
            if (dateCheck >= startDate && dateCheck <= endDate)
                filtered.push(campaigns[i]);
        }