Timestamp Microservice: I'm not sure why I'm not passing this one test

Tell us what’s happening:

I’m not exactly sure why this test is not passing:

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

I did some manual testing of various scenarios with passing variations like “/api/sfafasf”, “/api/2018-sd-22”, “–” and on all of them I got this error message object return. What could be a reason for this test failing on me?

app.get('/api/:date', (req, res) => {
  const extractedValue = req.params.date;

  let date = extractedValue.includes('-') ? new Date(extractedValue) : new Date(parseInt(extractedValue));
  if (date instanceof Date && !isNaN(date.valueOf())) {
    const unixDate = date.getTime();
    const utcDate = date.toUTCString();

    return res.json({ unix: unixDate, utc: utcDate });
  } else {
    return res.json({ error: date.toString() });

app.get('/api', (req, res) => {
  const date = new Date();
  const unixDate = date.getTime();
  const utcDate = date.toUTCString();

  let dateObj = { unix: unixDate, utc: utcDate };


Your project link(s)

solution: https://replit.com/@konstantinik1/timestamp-microservice

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36

Challenge: Timestamp Microservice

Link to the challenge:

Going into the network tab, for that test, when I run FCC’s API, it is sending this:

Request URL: https://timestamp-microservice.freecodecamp.rocks/api/05%20October%202011

Those %20 are space characters, so this is really sending “05 October 2011”.

The FCC API is returning:

{"unix":1317772800000,"utc":"Wed, 05 Oct 2011 00:00:00 GMT"}

Your API is returning:

{"unix":5,"utc":"Thu, 01 Jan 1970 00:00:00 GMT"}

That is a big difference. Note that that unix code is supposed to be milliseconds since Jan 1, 1970. You are calculating “05 October 2011” to be 5 ms after the start of Jan 1, 1970. That is off by quite a bit.

I would look there.

1 Like

Thanks a lot, I’m gonna look into that!

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