I have a form in a website that goes to a node.js backend, and in the form there’s two date selectors. When trying to pick a date I can’t get any results other than two arbitrary dates, which are Feb 1st 2024 and Oct 1st 2024.
I am not sure if I am missing something obvious or what is causing this bug.
What should I be doing different?/How can I get the date inputs to give the correct date?
HTML:
<div class="container parse">
<form action="/parse" method="post">
<select name="location" id="location" required>
<option value="none" selected disabled hidden>Institución</option>
<option value="1"> Arcoiris EP </option>
<option value="1"> Albores ES </option>
</select>
<input type="date" name="startDate" id="startDate" required>
<input type="date" name="endDate" id="endDate" required>
<select name="employee" id="employee">
<option value="none" selected disabled hidden>Empleado</option>
<option value="none" >Todos</option>
<!--list of employees from js array-->
</select>
<button class="btn"
<!--htmx post req-->
> Buscar </button>
</form>
</div>
and the post request looks like:
app.post('/parse', (req, res) => {
params = {
location: req.body.location,
employee: req.body.employee,
startDate: turnToDate(req.body.startDate),
endDate: turnToDate(req.body.endDate),
};
console.log(`The parameters to search for are:
start date: ${params.startDate} end date: ${params.endDate}
for employee: ${params.employee}`) //***
const displayTable = mdb.parseMainTable(parseTable,
params.startDate, params.endDate, params.employee);
const stringifiedHTML = createHTML(displayTable);
res.send(stringifiedHTML);
//parseMainTable function from mdb module:
const parseMainTable = (parseTable, startDate, endDate, employee) => {
let employeeFilteredTable = [];
let displayTable = [];
if (employee != 'none') {
employee = Number(employee);
employeeFilteredTable = parseTable.filter((el) => (el.id == employee));
} else {
employeeFilteredTable = parseTable
};
displayTable = employeeFilteredTable.filter((el) => (
el.timestamp >= startDate
&&
el.timestamp <= endDate
));
return displayTable;
};
*** always logs “The parameters to search for are:
start date: Thu Feb 01 2024 00:00:00 GMT-0300 (Brasilia Standard Time) end date: Tue Oct 01 2024 00:00:00 GMT-0300 (Brasilia Standard Time)
for employee: none” or
The parameters to search for are:
start date: Tue Oct 01 2024 00:00:00 GMT-0300 (Brasilia Standard Time) end date: Tue Oct 01 2024 00:00:00 GMT-0300 (Brasilia Standard Time)
for employee: none
The list therefore ends up containing items in this arbitrary date range and nowhere else.