【发布时间】:2019-01-22 17:41:16
【问题描述】:
我正在尝试检查当前过滤器对象是否落入日期范围并基于数据返回 boolean ,如果数据不在日期范围内,则应过滤掉该对象。使用下面的代码,它总是返回数据。知道什么是实现此任务的错误或正确方法吗?
main.ts
function mapResponse() {
const _startDate = "2018-12-15";
const _endDate = "2019-01-15";
_startDate = moment.utc(_startDate || twentyfourMonthsAgo, ["YYYY-MM-DD", "MM-DD-YYYY", "MM/DD/YYYY"]).format("YYYY-MM-DD");
_endDate = moment.utc(_endDate || today, ["YYYY-MM-DD", "MM-DD-YYYY", "MM/DD/YYYY"]).format("MM/DD/YYYY");
const response = [
{
rxNumber: "15139",
rxIssueDate: "",
fillDate: "2019-01-03",
quantityRemaining: "3",
prescribedNoOfRefills: "3",
currentFillNumber: "0"
},
{
rxNumber: "16131",
rxIssueDate: "",
fillDate: "2019-12-03",
quantityRemaining: "3",
prescribedNoOfRefills: "3",
currentFillNumber: "0"
}
]
response = response.filter(
function renameSpecialtyAttributesToPBM(specialtyRx: any) {
const mappedRx = specialtyRx as Partial < any > ;
const dateFilter = checkDateRange(_startDate, _endDate, specialtyRx.fillDate);
if (!dateFilter) {
return false;
}
mappedRx.fillDate = specialtyRx.fillDate;
mappedRx.refillEligible = !!mappedRx.refillStatusText;
mappedRx.renewEligible = !!specialtyRenewStatus;
return true;
});
}
return response;
}
checkDateRange.ts
function checkDateRange(startDate: any, endDate: any, fillDate: RxDetailsEntity): boolean {
if (fillDate > startDate && fillDate < endDate) {
return true;
}
return false;
}
mapResponse 的预期输出应该是
response = [
{
rxNumber: "15139",
rxIssueDate: "",
fillDate: "2019-01-03",
quantityRemaining: "3",
prescribedNoOfRefills: "3",
currentFillNumber: "0"
}]
【问题讨论】:
标签: javascript angular typescript date-range