Can't fix 2 bugs (Timestamp Microservice)

Tell us what’s happening:
I’m receiving 2 errors:

  1. A request to /api/1451001600000 should return { unix: 1451001600000, utc: "Fri, 25 Dec 2015 00:00:00 GMT" }
  2. Your project can handle dates that can be successfully parsed by new Date(date_string)

When I go to [myProjectLink]/api/1451001600000, it’s returning a json { unix: 1451001600000, utc: "Fri, 25 Dec 2015 00:00:00 GMT" } which is exactly what they want… I don’t understand what they mean on the second error and how am I not doing that?

I appreciate all the time and effort I will receive! Thanks

Your project link(s)

solution: boilerplate-project-timestamp - Replit

Your browser information:

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

Challenge: Timestamp Microservice

Link to the challenge:

I think it has something to do with this line here:

const date = new Date(convertion);

The error you’re getting specifically says "Your project can handle dates that can be successfully parsed by new Date(date_string) " and during your conversion you’re passing in a number if it’s unix.

Did you try just passing in the date string directly, or converting it to a number later if needed?

1 Like

Log your route inputs and outputs. For the failing tests you’ll see:

req.params: {"dateStr":"1451001600000"}
{ unix: '1451001600000', utc: 'Fri, 25 Dec 2015 00:00:00 GMT' }

The spec says unix should be a number.

req.params: {"dateStr":"05 October 2011, GMT"}
{ error: 'Invalid Date' }

That’s a valid date, with no dashes.

1 Like

Thank you everyone for your response!

The problem was my logic again (as always). First, my regex, I was checking if the request matches a dash (which I assumed would make their request a valid date).

But, there was a much better approach to that:

function isValidDate(d) {
  return d instanceof Date && !isNaN(d);
}

This function checks if the argument passed in is a valid date. Which does not require the logic I came up with (regex).

After fixing that logic, I played around with my if/else statements and apparently it worked.

I push myself to the limits on how far can I do stuff without googling, but ended up complicating stuff. I should be aware that googling is part of a developer’s job, and should google more often because if I didn’t, I wouldn’t realize there was a much easier approach to checking a valid date :rofl:

1 Like