Tell us what’s happening:
Hi, I have only one error message before passing the test:
Your project can handle dates that can be successfully parsed by new Date(date_string)
I guess it was meant to see if I use Data.parse in my code which I have but I still get this error message. Please help me to find what I’m missing!
That’s my code so far:
app.get("/api/:date", function (req, res) {
let userInput = req.params.date;
let numberInput = Number(userInput);
let userDay = new Date(userInput);
let epoch = Date.parse(userInput);
let ud = userDay.toUTCString();
if (userInput.length > 10) { //1451001600000
let msDate = new Date(numberInput);
let humanDate = msDate.toUTCString();
if (humanDate == ‘Invalid Date’) {
res.json({error: ‘Invalid Date’});
};
res.json({“unix”: numberInput,
“utc”: humanDate});
}else if (userInput.length <= 10){ //2015-12-25
if (ud == ‘Invalid Date’) {
res.json({error: ‘Invalid Date’});
}
res.json({“unix”: epoch,
“utc”: ud});
}
});
I solved!
Put my code here for someone with the same issue later.
app.get("/api/:date", function (req, res) {
let userInput = req.params.date;
let userDay = new Date(userInput);
let numberInput = Number(userInput);
let msDate = new Date(numberInput);
let humanDate = msDate.toUTCString();