Tell us what’s happening:
Hello!! I was trying to solve APIs and Microservices Projects - Timestamp Microservice problem. I guess I did everything correctly but my code can’t pass tests. Can someone test my API ? Thanks!!!
Your code so far
app.get("/api/timestamp/", function(req, res) {
console.log({unix: Date.now(), utc: Date()});
res.json({unix: Date.now(), utc: Date()});
return;
})
app.get("/api/timestamp/:date_string", function(req, res) {
var dateString = req.params.date_string;
if (/\d{5,}/.test(dateString)) {
var dateInt = parseInt(dateString);
var unix = dateInt;
var utc = new Date(dateInt).toUTCString();
console.log({ unix: unix, utc: utc });
res.json({ unix: unix, utc: utc });
return;
}
var dateObject = new Date(dateString);
if (dateObject.toString() === “Invalid Date”) {
console.log({ error: “Invalid Date” });
res.json({ error: “Invalid Date” });
return;
} else {
console.log({ unix: dateObject.getTime(), utc: dateObject.toUTCString() });
res.json({ unix: dateObject.getTime(), utc: dateObject.toUTCString() });
return;
}
})
Your browser information:
User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0
.
Challenge: undefined
Link to the challenge: