Back End Development and APIs Projects - Timestamp Microservice

Tell us what’s happening:
It seems like all the output is coming out correctly but I’m still failing tests 2 and 5.

Your project link(s)

solution: boilerplate-project-timestamp - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 OPR/97.0.0.0

Challenge: Back End Development and APIs Projects - Timestamp Microservice

Link to the challenge:

test 1: A request to /api/:date? with a valid date should return a JSON object with a unix key that is a Unix timestamp of the input date in milliseconds (as type Number)

This method of getting unix fails test 1 . You will get seconds floored, but you needed to get the value in milliseconds to pass the test.

unix: Math.floor(new Date(req.params.date) / 1000)

Use this method instead to get unix:

date.getTime()


test 5: Your project can handle dates that can be successfully parsed by new Date(date_string).

This test should pass after fixing the previous error.

This is not needed for passing the test, but i just felt like mentioning it.
About this condition used for your if else statement.

line 68: date instanceof Date && !isNaN(date)

‘isNaN’ condition is redundant in your code, the ‘instanceof’ condition already suffices to determine if the date is valid.

If you are using ‘isNaN’ to determine if ‘req.params.date’ is a number, you should be using ‘!isNaN(req.params.date)’ for second condition to make sure it is a number.

And ‘isNaN(req.params.date)’ for your first condition to make sure it is not a number.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.