Timestamp Microservice Error

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" });
  }
})

@deepjindal65 Welcome to the freeCodeCamp forum.

I would like to see the code you wrote. Also, everyone and I could check the code what the problem is.

Thank you!

Hi

I have edited the post with code.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.