Timestamp-microservice-help

Hey guys,
I had been working on the timestamp microservice project from the APIs ad Microservices curriculum and I am facing the following issue.

  • The test case : Your project can handle dates that can be successfully parsed by new Date(date_string) is the only test case that is not passing.

I had tried checking out different forums to try get to the solution but am not able to do so.

Could someone help me sort this out?

Project Link: Project Link

Source Code: Source Code

I had a similar issue when working on this project. In my case, I noticed that the FCC version of the service and my version differed on a specific date_string format due to the time zone being assumed. If you look at the documentation for Date.parse() on Mozilla (see the following: Date.parse()), one of the date_string formats accepted by the parse() method assumes the time is based on the local time zone where your machine is physically. If you want to correct it to use GMT, you can convert the date_string to an ISO format date_string, or handle it manually a different way.

I’m assuming there’s probably an easier and better solution for this, but since using the ISO format worked for me, I didn’t pursue any other options.

You’re doing a lot of unnecessary work parsing the string.

In the case that you’re given milliseconds like in /api/1451001600000, convert req.params.date to a number, then pass that number straight into new Date().

In the case that you’re given anything else, toss req.params.date straight into new Date().


An easy way to test if something converts cleanly to a number without regular expressions is something like this using the Number constructor.

const someNum = Number(someString);
if (Number.isNaN(someNum)) {
  // someString couldn't convert to a number
}

And for your convenience, check out the toUTCString() method on the Date object.

Thanks a bunch @colinthornton, worked like a charm, did not realize I was performing a lot of redundant operations.

Hi brother…I’ve been stuck for hours on this project. Can you plsss reply with the code that passed the test or can you kindly take your time to email me muhammedko420@gmail…thinking the answer might be blocked here. Thanks

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