Problem with one of the tests in timestamp microservice project

Tell us what’s happening:

Hello, I have done the time stamp micro service project and it keeps failing one test:
Your project can handle dates that can be successfully parsed by new Date(date_string).
I don’t know exactly what it means but I think it has something to do with the fact that I have used the Luxon library instead of the library that is used by fcc.
Thanks for your time :slight_smile: .

Your project link(s)

repl.it: https://replit.com/@Alons21/Timestamp-MicroserviceAlonsoQuiros#README.md
solution: https://timestamp-microservicealonsoquiros.alons21.repl.co

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0.

Challenge: Timestamp Microservice

Link to the challenge:

I modified this relevant bit of your code with some logging:

  //If there is any letter in the request, return invaliid date
  if (/[a-zA-Z]/.test(input)) {
    console.log(input);
    console.log({error: "Invalid date", details: "The date contains letters"});
    return res.json({error: "Invalid date", details: "The date contains letters"});
  }

This test is sending 05 October 2011, and that is parseable by Date(). My modifications above yield

05 October 2011
{ error: 'Invalid date', details: 'The date contains letters' }

on the console. However, it’s a valid date. Always log your route inputs and outputs when debugging. It’s the first thing I do after I break something.

1 Like

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

new Date('05 October 2011') returns a valid date (try it in browser console), but your code thinks it’s an invalid date.
I think you’ve just over complicated the input parsing. Instead of just trying to create a date from the input and see if it’s valid, you’re trying to re-implement Date constructor.

1 Like

Both answers were usefull, now it is solved, thank both of you (:

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