Tell us what’s happening:
I’m not exactly sure why this test is not passing:
- Your project can handle dates that can be successfully parsed by
new Date(date_string)
I did some manual testing of various scenarios with passing variations like “/api/sfafasf”, “/api/2018-sd-22”, “–” and on all of them I got this error message object return. What could be a reason for this test failing on me?
app.get('/api/:date', (req, res) => {
const extractedValue = req.params.date;
let date = extractedValue.includes('-') ? new Date(extractedValue) : new Date(parseInt(extractedValue));
if (date instanceof Date && !isNaN(date.valueOf())) {
const unixDate = date.getTime();
const utcDate = date.toUTCString();
return res.json({ unix: unixDate, utc: utcDate });
} else {
return res.json({ error: date.toString() });
}
});
app.get('/api', (req, res) => {
const date = new Date();
const unixDate = date.getTime();
const utcDate = date.toUTCString();
let dateObj = { unix: unixDate, utc: utcDate };
res.json(dateObj);
});
Your project link(s)
solution: https://replit.com/@konstantinik1/timestamp-microservice
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36
Challenge: Timestamp Microservice
Link to the challenge: