如何将今天开始的所有活动带到30天?
我做过这个管道,但它不起作用
有一系列事件,需要在30天内只带来dateStart
的事件,我该怎么做呢? dateStart
和Date.now()
+ 30天
import { Pipe, PipeTransform } from '@angular/core';
import { SupplyEvent } from "../../models/supplyEvent";
@Pipe({
name: 'toBeginFilter'
})
export class ToBeginFilterPipe implements PipeTransform {
toBegin (SupplyEvent) {
if (SupplyEvent.dateStart >= Date.now() + (30)) {
return SupplyEvent
}
}
transform(SupplyEvents: SupplyEvent[]): any {
if (!SupplyEvents) return SupplyEvents
return SupplyEvents.filter(this.toBegin)
}
}
答案 0 :(得分:1)
哎呀,不是3
! JavaScript日期对象基于时间戳。
30天= 30 * 24 * 3600 * 1000
export class ToBeginFilterPipe implements PipeTransform {
// assuming SupplyEvent.dateStart is timestamp.
toBegin (SupplyEvent) {
return Date.now() - SupplyEvent.dateStart <= (30*24*3600*1000);
}
transform(SupplyEvents: SupplyEvent[]): any {
if (!SupplyEvents) return SupplyEvents
return SupplyEvents.filter(this.toBegin)
}
}