Hello I'm trying to filter out data that shouldn't be on this schedule

I currently have this function that has the filter data
const formatData = (input: any) => {
const data: any = _.uniqBy(input.Value, 'Activity Id');
const formatDate = (text: any) =>
moment(text as string).format('YYYY-MM-DD');
// Data being returned from thirdparty isn't filtering out certain data
const filtered = data.filter(
(e: any) =>
(formatDate(e['Start Date ']) <= formatDate(query.Start_Date) &&
formatDate(e['End Date']) >= formatDate(query.End_Date)) ||
(formatDate(e['Start Date ']) >= formatDate(query.Start_Date) &&
formatDate(e['End Date']) <= formatDate(query.End_Date)) ||
(formatDate(e['Start Date ']) >= formatDate(query.Start_Date) &&
formatDate(e['Start Date ']) <= formatDate(query.End_Date))
);
return { Value: filtered };
};
The filter isn't correct I'm trying to figure simple way of filtering out dates that aren't between those two query req.query.end and start
This sample of the data set
{
Value: [
{
"Activity Id": "05005413-05",
"Activity Name": "UNIT 1 ASBESTOS REMOVAL; PERMITS (CSP, FSI, HWP)",
"Start Date ": "2020-11-09 07:00:00.0",
"End Date": "2021-05-17 15:00:00.0",
"Work Group Name": "PSCF",
"Unit ": "01",
Status: "READY",
"Work Pln Factor": ", ",
},
{
"Activity Id": "B2119",
"Activity Name": "Begin Work Week 2119",
"Start Date ": "2021-05-10 00:00:00.0",
"End Date": "2021-05-10 00:00:00.0",
"Work Pln Factor": ", ",
},
{
"Activity Id": "B2118",
"Activity Name": "Begin Work Week 2118",
"Start Date ": "2021-05-03 00:00:00.0",
"End Date": "2021-05-03 00:00:00.0",
"Work Pln Factor": ", ",
},
{
"Activity Id": "04901693-05",
"Activity Name": "NEW LPRM IV TEST RE-SET PM FOR NEXT CYCLE.",
"Start Date ": "2021-04-23 01:00:00.0",
"End Date": "2021-04-23 03:00:00.0",
"Unit ": "02",
Status: "PLAN",
"Work Pln Factor": ", ",
},
{
"Activity Id": "04901693-04",
"Activity Name": "20C037 IV CURVES ON SELECTED U2 LPRM'S",
"Start Date ": "2021-04-22 07:00:00.0",
"End Date": "2021-04-22 15:00:00.0",
"Work Group Name": "PMI3",
"Unit ": "02",
Status: "PLAN",
"Work Pln Factor": ", ",
},
{
"Activity Id": "B2116",
"Activity Name": "Begin Work Week 2116",
"Start Date ": "2021-04-19 00:00:00.0",
"End Date": "2021-04-19 00:00:00.0",
"Work Pln Factor": ", ",
},
{
"Activity Id": "B2121",
"Activity Name": "Begin Work Week 2121",
"Start Date ": "2021-05-24 00:00:00.0",
"End Date": "2021-05-24 00:00:00.0",
"Work Pln Factor": ", ",
},
{
"Activity Id": "05005413-35",
"Activity Name": "SCAFFOLD SUPPORT TEAM - CARPENTERS & LABORERS",
"Start Date ": "2020-11-09 06:00:00.0",
"End Date": "2021-06-03 16:00:00.0",
"Work Group Name": "PSCF",
"Unit ": "01",
Status: "READY",
"Work Pln Factor": ", ",
},
{
"Activity Id": "04912309-35",
"Activity Name": "SCAFFOLD SUPPORT TEAM - CARPENTERS & LABORERS",
"Start Date ": "2020-11-09 06:00:00.0",
"End Date": "2021-06-30 16:00:00.0",
"Work Group Name": "PSCF",
"Unit ": "01",
Status: "READY",
"Work Pln Factor": ", ",
},
{
"Activity Id": "04224121-04",
"Activity Name": "REBUILD CAT ID 0011698252 AND RETURN TO STORES.",
"Start Date ": "2021-05-03 07:00:00.0",
"End Date": "2021-05-05 15:00:00.0",
"Work Group Name": "PME1",
"Unit ": "03",
Status: "READY",
"Work Pln Factor": ", ",
},
];
}
So if the start time if start=23-JUN-2021 end=19-APR-2021 this was be the expected returned result
{
Value: [
{
"Activity Id": "05005413-05",
"Activity Name": "UNIT 1 ASBESTOS REMOVAL; PERMITS (CSP, FSI, HWP)",
"Start Date ": "2020-11-09 07:00:00.0",
"End Date": "2021-05-17 15:00:00.0",
"Work Group Name": "PSCF",
"Unit ": "01",
Status: "READY",
"Work Pln Factor": ", ",
},
{
"Activity Id": "B2119",
"Activity Name": "Begin Work Week 2119",
"Start Date ": "2021-05-10 00:00:00.0",
"End Date": "2021-05-10 00:00:00.0",
"Work Pln Factor": ", ",
},
{
"Activity Id": "B2116",
"Activity Name": "Begin Work Week 2116",
"Start Date ": "2021-04-19 00:00:00.0",
"End Date": "2021-04-19 00:00:00.0",
"Work Pln Factor": ", ",
},
{
"Activity Id": "05005413-35",
"Activity Name": "SCAFFOLD SUPPORT TEAM - CARPENTERS & LABORERS",
"Start Date ": "2020-11-09 06:00:00.0",
"End Date": "2021-06-03 16:00:00.0",
"Work Group Name": "PSCF",
"Unit ": "01",
Status: "READY",
"Work Pln Factor": ", ",
},
{
"Activity Id": "04912309-35",
"Activity Name": "SCAFFOLD SUPPORT TEAM - CARPENTERS & LABORERS",
"Start Date ": "2020-11-09 06:00:00.0",
"End Date": "2021-06-30 16:00:00.0",
"Work Group Name": "PSCF",
"Unit ": "01",
Status: "READY",
"Work Pln Factor": ", ",
},
];
}
This is the function that handles displaying the bars in the frontend
const timeLine = (data: any, day: string) => {
return (data || []).map((activity: any) => {
const startMoment = moment(activity['Start Date ']);
const endMoment = moment(activity['End Date']);
const dayStart = moment(day, 'MMM D');
const duration =
moment.duration(endMoment.diff(startMoment));
let hours = Math.abs(duration.asHours());
if (hours === 1 || hours === 0) hours = 3;
let offSetX =
moment.duration(startMoment.diff(dayStart)).asHours() + 1;
const result = {
numberOfUnits: hours === 0 ? 1 : hours,
offSetX,
unitColor: getUnitColor(activity['Unit '], userPlant)
};
return result;
});
};