Tell us what’s happening:
I’ve passed all the tests except for these one:
" Your project can handle dates that can be successfully parsed by new Date(date_string) "
Using all the test examples given in the statement my API works accordingly. Can someone help me? Here’s my code
app.get('/api/:dateString', (req, res) => {
const {dateString} = req.params
const unix = Date.parse(dateString)
let data
if (isNaN(unix)){
if (/^\d+$/.test(dateString)){
const dateNumber = new Number(dateString);
data = {'unix': new Date(dateNumber).getTime(), 'utc': new Date(dateNumber).toUTCString()}
}else{
data = {'error': 'Invalid Date'}
}
}else{
data = {'unix': unix, 'utc': new Date(unix).toUTCString()}
}
return res.json(data)
})
Your project link(s)
solution:
githubLink: GitHub - GorreriFranco/boilerplate-project-timestamp: A boilerplate for a freeCodeCamp project.
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0
Challenge: Timestamp Microservice
Link to the challenge: