Typescript如何过滤数据创建日期和到期日期
如何筛选当前日期在创建日期内且当前日期不超过有效期的产品?
async getAllproduct():Promise<Array<Product>>{
const currentDate = new Date(Date.now() - 86400 * 7000);
const product: Array<Product> = await this.findProductStatus(
currentDate,
ProductStatus.active
);
const activeProduct = product.filter((product) => product.CreatedDate > currentDate && product.ProductEndAt < currentDate);
return activeProduct;
}
我不知道逻辑是否 <product.CreatedDate >当前日期 &&产品.ProductEndAt <当前日期
>这是正确的,请纠正我,我只想过滤当前日期(Date.now)在 createdDate
内且不超过到期日期的产品
how can I filter the product whose current date is within the created date and the current date does not exceed the expiration date?
async getAllproduct():Promise<Array<Product>>{
const currentDate = new Date(Date.now() - 86400 * 7000);
const product: Array<Product> = await this.findProductStatus(
currentDate,
ProductStatus.active
);
const activeProduct = product.filter((product) => product.CreatedDate > currentDate && product.ProductEndAt < currentDate);
return activeProduct;
}
I don't know if the logic <product.CreatedDate > currentDate && product.ProductEndAt < currentDate
> here is right, please correct me on this, I just want to filter the product that has the current date (Date.now) is within the createdDate
and does not exceed the expiration date
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的逻辑应该使用
date > CreatedDate
- 日期晚创建日期date ProductEndAt
- 日期早于到期日期Your logic should use
date > CreatedDate
- date is after the created datedate < ProductEndAt
- date is before the expiration date