I’m failing the last two testcases on the timestamp microservice projects even though it works very will … can anyone help?
code:
// empty date is given
app.get("/api/", (req, res) => {
const date = new Date();
res.json({ unix: date.getTime(), utc: date.toUTCString() });
});
//valid date is given
app.get("/api/:date", (req, res) => {
let dateValue = req.params.date;
// checks if it's a number
if (/^-?\d+$/.test(dateValue)) {
dateValue = parseInt(dateValue);
}
const date = new Date(dateValue);
if (date.getTime()) {
res.json({ unix: date.getTime(), utc: date.toUTCString() });
} else {
res.json({ error: "Invalid Date" });
}
});
link to repl:
https://replit.com/@MoroOwusu/boilerplate-project-timestamp#server.js