Stuck on Timestamp Microservice

Tell us what’s happening:
I’m stuck on test 2 and 5:

A request to /api/:date? with a valid date should return a JSON object with a unix key that is a Unix timestamp of the input date in milliseconds

Your project can handle dates that can be successfully parsed by new Date(date_string)

My code does this both. Don’t know what I’m missing.
Can someone please explain the tests to me.

Your project link(s)

solution: boilerplate-project-timestamp - Replit

Your browser information:

User Agent is: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:98.0) Gecko/20100101 Firefox/98.0

Challenge: Timestamp Microservice

Link to the challenge:

I took a quick glance. I’m not sure but I would add other test links to your index.html for testing with invalid dates. such as month 13 or day over 31 etc and see what you get. I noticed in your code

app.get("/api/:date", (req, res) => {
  let dateString = req.params.date;

  if (!isNaN(Date.parse(dateString))) {
    let dateObject = new Date(dateString);
    res.json({ unix: dateObject.valueOf(), utc: dateObject.toUTCString() });
  } else if (/\d{5,}/.test(dateString)) {
      let dateInt = parseInt(dateString);
      res.json({ unix: dateInt, utc: new Date(dateInt).toUTCString() });
  } else {
    res.json({ error: "Invalid Date" });
  }

});

the regex only checks for digits. That does not mean those digits are valid months or days?

edit

I should also mention fire up your replit and submit link. My connection sometimes lags so much I have to submit multiple times for the tests to pass.

1 Like

Thank you so much. But later I found the solution. I was busy today I forgot to delete this post.
The code you quoted is the final code which is working