Tell us what’s happening:
My Code passes all the test except
" Your project can handle dates that can be successfully parsed by new Date(date_string)
"
However, my code clearly does this anyway. I’ve tried other users’ code and multiple different solutions but still no success. What am I missing?
Your code so far
app.get("/api/timestamp", (req, res) => {
let now = new Date();
res.json({
unix: now.getTime(),
utc: now.toUTCString(),
});
});
app.get("/api/timestamp/:date_string", (req, res) => {
let date_string = req.params.date_string;
let passedInValue = new Date(date_string);
if (parseInt(date_string) > 10000) {
let unixTime = new Date(parseInt(date_string));
res.json({
unix: unixTime.getTime(),
utc: unixTime.toUTCString(),
});
}
if (passedInValue == "Invalid Date") {
res.json({ error: "Invalid Date" });
} else {
res.json({
unix: passedInValue.valueOf(),
utc: passedInValue.toUTCString(),
});
}
});
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
.
Challenge: Timestamp Microservice
Link to the challenge: