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)
solution: https://replit.com/@ayobamimichael/boilerplate-project-timestamp-2
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
jenovs
February 2, 2022, 5:58pm
#2
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:
Blockquote
if (date_string.includes(’-’) || date_string.includes(’ ')){
const dateNew = new Date(date_string);
timeObj['unix'] = dateNew.getTime();
timeObj['utc'] = dateNew.toUTCString();
}
jenovs
February 3, 2022, 1:18pm
#4
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.
Blockquote
if (date_string.includes(’-’) || date_string.includes(’ ‘) || date_string.includes(’,’)
and am thinking maybe regular expression will work for dates containing( . , ; etc)
1 Like
jenovs
February 3, 2022, 2:05pm
#6
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”.
system
closed
August 5, 2022, 2:05am
#7
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.