I cant pass the timestampe test because of the challenge that states handling parsed dates.
below is code that passes everything except for that challenge.
app.get('/api/:date?', (req, res)=>{
if(req.params.date == null){
const nowdate = new Date().toUTCString()
res.json({unix: Date.parse(nowdate), utc: nowdate})
} else if (!req.params.date.match(/-/g)){
const parsed = parseInt(req.params.date)
res.json({unix: parsed, utc: new Date(parsed).toUTCString()})
} else {
const paramdate = new Date(req.params.date);
if(paramdate == 'Invalid Date'){
res.json({error: 'Invalid Date'})
} else {
const myDate = new Date(req.params.date);
const gmtDate = myDate.toUTCString();
const otherDate = Date.parse(myDate);
res.json({utc: gmtDate, unix: otherDate});
}
}
})
if i take out where i use regex and parse a unix number in the url, it passes the above but fails obviously for not returning the unix number.
app.get('/api/:date?', (req, res)=>{
if(req.params.date == null){
const nowdate = new Date().toUTCString()
res.json({unix: Date.parse(nowdate), utc: nowdate})
} else {
const paramdate = new Date(req.params.date);
if(paramdate == 'Invalid Date'){
res.json({error: 'Invalid Date'})
} else {
const myDate = new Date(req.params.date);
const gmtDate = myDate.toUTCString();
const otherDate = Date.parse(myDate);
res.json({utc: gmtDate, unix: otherDate});
}
}
})
So i am assuming it has something to do with how i am either parsing or searching for the unix number from the url. This is the 3rd attempt at building this, after passing 3 of the other backend tests.
https://replit.com/@RobertWisnewski/boilerplate-project-timestamp#index.js