我编写此代码以获取有关日期范围的总和,但我正面临这个问题
运营商'>'不能应用于类型'Iterable'和 '日期'。
这是我的代码
export function getTotalYearCosts(valueItem: ValueItem, allCosts: Map<string, Costs>): TotalCosts {
const totalYearCosts = { planned: 0, actual: 0 };
const test = allCosts.map(({created}) => created);
const Q1 = new Date('2018-01-01');
const Q2 = new Date('2018-04-01');
totalYearCosts.actual = valueItem.actualCostIds
.map(costId => allCosts.get(costId, emptyCosts()).costs)
.filter(costs => test > Q1 && test < Q2)
.reduce((reduction, costs) => reduction + costs, 0);
totalYearCosts.planned = valueItem.plannedCostIds
.map(costId => allCosts.get(costId, emptyCosts()).costs)
.reduce((reduction, costs) => reduction + costs, 0);
return totalYearCosts;
}
费用的接口
export interface Costs {
id: string;
created: Date;
costs: number;
// costType: number;
type: number;
reference: string;
comment: string;
}
答案 0 :(得分:0)
我已经解决了这个问题。
export function getTotalYearCosts(valueItem: ValueItem, allCosts: Map<string, Costs>): ActualCosts {
const totalYearCosts = { actual: 0, planned: 0, Q1: 0, Q2: 0, Q3: 0, Q4: 0 };
const iter = allCosts[Symbol.iterator]();
for (let i = 0; i < valueItem.actualCostIds.length; i++) {
const costID = valueItem.actualCostIds[i];
if (allCosts.get(costID).created.getMonth() < 3 && allCosts.get(costID).created.getMonth() >= 0 ) {
totalYearCosts.actual += allCosts.get(costID).costs;
totalYearCosts.Q1 += allCosts.get(costID).costs;