Help Needed with Exercise Tracker API - Date Formatting Issue:
I am stuck at the /api/users/:_id/logs endpoint. Can anyone help me? Please help me by clicking on my repository link the program code is in the server4.js file
Specific Issue:
The test case #15 is failing:
“The date property of any object in the log array should be a string in dateString format”
i get the same error, and still dont know how to pass it, can you find the solution? I check the response and it have exactly type as the example.
this is my code GitHub - nejato/timestamp-microservices
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.
The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.
I failed test15 several times, before finding a comment, that it had to do with handling invalid dates, the test cases check that. Return current in that case.
I checked your code, seems you’re checking for that already.
Additionally I’ve checked for the format yyyy-mm-dd.
// Helper to validate yyyy-mm-dd and check if it's a real date
// otherwise, return current date
function parseValidDate(dateStr) {
if (typeof dateStr !== 'string')
return new Date();
dateStr = dateStr.trim();
// Regex for yyyy-mm-dd
const regex = /^\d{4}-\d{2}-\d{2}$/;
if (!regex.test(dateStr))
return new Date();
const date = new Date(dateStr);
// Check for invalid date
if (isNaN(date.getTime()))
return new Date();
return date;
}