Tell us what’s happening:
[SPOILER]
Code contains solution.
PROBLEM -
Your project can handle dates that can be successfully parsed by new Date(date_string)
I have used this in my code multiple times yet the error occurs. Need Help!
let responseObject = {};
app.get('/api', (req, res) => {
responseObject['unix'] = new Date().getTime();
responseObject['utc'] = new Date().toUTCString();
res.json(responseObject);
});
app.get('/api/:date', (req, res) => {
let date = req.params.date;
console.log(date);
if(date.includes('-')){
responseObject['unix'] = new Date(date).getTime();
responseObject['utc'] = new Date(date).toUTCString();
console.log(responseObject);
} else {
responseObject['unix'] = Number(date);
responseObject['utc'] = new Date(Number(date)).toUTCString();
console.log(responseObject);
}
if(!responseObject['unix'] || !responseObject['utc']) {
res.json({error: 'Invalid Date'});
}
res.json(responseObject);
});
Your project link(s)
solution: boilerplate-project-timestamp (1) - Replit
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
Challenge: Back End Development and APIs Projects - Timestamp Microservice
Link to the challenge: