Timestamp Microservice - Code works but one test failing

Hello - I think I have completed the challenge but I am failing on one test… I’d really appreciate any help, I’m sure I’ve got an error somewhere but I’m not sure how to search for the answer to such a specific problem online / on the forums.

This is the test / output:
// running tests
It should handle a valid unix date, and return the correct unix timestamp
// tests completed

And my code is on Glitch here:

Or also below:

// Timestamp functionality...
app.get('/api/timestamp/:date_string?', (req, res) => {
  // Get query from URL
  let input = req.params.date_string;
  let date;
  // Create regex x2 for checks...
  let regexUTC = /([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/;
  let regexUnix = /\d{5,}/;
  // Handle no given date
  if (!input) {
    date = new Date();
  } else {
    // Check if valid
    if (regexUTC.test(input) == true) {
      date = new Date(Date.parse(input));
    } else if (regexUnix.test(input) == true) {
      date = new Date(input * 1000);
    } else {
      res.json({"error": "Invalid Date"});
  res.json({"unix": date.getTime(), "utc" : date.toUTCString() });


You are not returning back the correct value for unix. For example, if I make the following request:


I expect to see the following response returned

{"unix":1482624000000, "utc":"Sun, 25 Dec 2016 00:00:00 GMT"}

but instead yours returns:

{"unix":1482624000000000," utc":"Mon, 26 Jun 48952 00:00:00 GMT"}
1 Like

Thank you!

I will work it out and re-write it tomorrow!