Hi Everyone
So, what should have been a 30-min challenge has now been going on for 3 hours, and I am not getting anywhere. I have explored the Date object and methods back and forth, and have tried so many things, and nothing works. I don’t know what I am doing wrong here, but virtually all tests keep failing.
Even differentiating between valid and invalid time parameters isn’t working. Maybe it’s just one of those days, but I’d really appreciate some guidance.
Here is the replit: boilerplate-project-timestamp - Replit
And here is the relevant function (line 28 on the replit):
app.get("/api/:date", (req, res) => {
console.log(req.params.date);
let d = new Date(req.params.date);
console.log(d);
//if the date object returned as valid
if (d !== "Invalid Date") {
console.log("json");
return res.status(200).
json({
unix: Date.parse(d),
utc: d.toUTCString()
});
};
//if the date object is invalid, but the params are a valid number (ie timestamp)
if (Number(req.params.date)) {
d = Number(req.params.date);
return res.status(200)
.json({
unix: d,
utc: new Date(d).toUTCString()
})
};
//invalid timestamp
return res.status(400)
.json({
error : "Invalid Date"
});
});
Thank you!