Tell us what’s happening:
The last 2 tests fails:
- An empty date parameter should return the current time in a JSON object with a unix key
- An empty date parameter should return the current time in a JSON object with a utc key
Even though it is working as expected. It seems to be a common issue (not a code issue) but cant find how to fix it, please help, thanks !
app.get("/api/:date?", function (req, res) {
if (req.params.date === '' || req.params.date === undefined) {
const current = new Date();
return res.json({
unix: current.getTime(),
utc: current.toUTCString(),
});
}
const date = new Date(req.params.date);
if (date.toString() === 'Invalid Date') {
const date2 = new Date(parseInt(req.params.date, 10));
if (date2.toString() === 'Invalid Date') {
return res.json({ error : "Invalid Date" });
}
return res.json({
unix: date2.getTime(),
utc: date2.toUTCString(),
});
}
return res.json({
unix: date.getTime(),
utc: date.toUTCString(),
});
});
Your project link(s)
solution: https://boilerplate-project-timestamp.fffan64.repl.co
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36
.
Challenge: Timestamp Microservice
Link to the challenge: