An empty date parameter should return the current time tests failing

Tell us what’s happening:

The last 2 tests fails:

  • An empty date parameter should return the current time in a JSON object with a unix key
  • An empty date parameter should return the current time in a JSON object with a utc key

Even though it is working as expected. It seems to be a common issue (not a code issue) but cant find how to fix it, please help, thanks !

app.get("/api/:date?", function (req, res) {

  if (req.params.date === '' || req.params.date === undefined) {
    const current = new Date();
    return res.json({
      unix: current.getTime(),
      utc: current.toUTCString(),
    });
  }
  
  const date = new Date(req.params.date);
  if (date.toString() === 'Invalid Date') {
    const date2 = new Date(parseInt(req.params.date, 10));
    if (date2.toString() === 'Invalid Date') {
      return res.json({ error : "Invalid Date" });
    }
    return res.json({
      unix: date2.getTime(),
      utc: date2.toUTCString(),
    }); 
  }
    return res.json({
      unix: date.getTime(),
      utc: date.toUTCString(),
    });
});

Your project link(s)

solution: https://boilerplate-project-timestamp.fffan64.repl.co

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.128 Safari/537.36.

Challenge: Timestamp Microservice

Link to the challenge:

1 Like

Welcome, there.

When I submit your URL, all the tests pass. Have you fixed the issue?

thanks for your reply, unfortunately i didnt touch code, and it still fails when i submit the my url !
where are the tests run ? I’m in japan, so maybe there is a timezone difference or something ?
Is the current time checked on the response ?

Thanks again for trying to help me.

lol i have submitted the link from my phone instead of my laptop and it worked … go figure, thanks.

1 Like

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