My code is not passing this 'Your project can handle dates that can be successfully parsed by new Date(date_string)'

Tell us what’s happening:
Describe your issue in detail here.
Please I don’t understand this test.
'Your project can handle dates that can be successfully parsed by new Date(date_string)

Your project link(s)


Your browser information:

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

Challenge: Timestamp Microservice

Link to the challenge:

1 Like

This test is done with a string:

"05 October 2011, GMT"

In your code this will be handled by else clause where first line is:

const intValue = parseInt(date_string);

which will result in intValue to be 5 and therefore dateObject will be around 01.01.1970.

Thanks for the clue but I actually solved it by doing this:

if (date_string.includes(’-’) || date_string.includes(’ ')){
const dateNew = new Date(date_string);

  timeObj['unix'] = dateNew.getTime();
  timeObj['utc'] = dateNew.toUTCString();


Btw, "05,October,2011" is still a valid string. FCC tests are not testing with it, but your code won’t be able to handle such string.

After updating my code to this, it worked.

if (date_string.includes(’-’) || date_string.includes(’ ‘) || date_string.includes(’,’)

and am thinking maybe regular expression will work for dates containing( . , ; etc)

1 Like

You can just directly put the received date_string into new Date() no need to do any additional checks. If date_string is valid you’ll get a date object, if not then “Invalid Date”.

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