A request to /api/1451001600000 should return { unix: 1451001600000, utc: "Fri, 25 Dec 2015 00:00:00 GMT" }
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
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?
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