Tell us what’s happening:
Your project link(s)
solution: https://mongoosefc.herokuapp.com
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36
.
Challenge: Timestamp Microservice
Link to the challenge:
I am submitting my solution which is giving output as desired but tests are being failed. I am unable to understand why. Someone please help me.
app.get("/api/timestamp/:date?",function(req,res,next){
var date;
if(!req.params.date){
date = moment().utc()
res.json({unix:parseInt(date.format("x")),utc:date.format("ddd, DD MMM YYYY HH:mm:ss [GMT]")})
}
try {
var valid = moment(req.params.date).isValid();
if(valid){
date = moment(req.params.date);
res.json({unix:parseInt(date.format("x")),utc:date.format("ddd, DD MMM YYYY HH:mm:ss [GMT]")})
}else{
valid = moment(parseInt(req.params.date)).isValid();
if(valid){
date = moment(parseInt(req.params.date)).utc()
res.json({unix:parseInt(date.format("x")),utc:date.format("ddd, DD MMM YYYY HH:mm:ss [GMT]")})
}else{
res.json({ error : "Invalid Date" });
}
}
} catch (error) {
res.json({ error : "Invalid Date" });
}
})