Timestamp Microservice - can't pass 2 tests

Hey lovely codecampers, I’m having issues passing tests on the Timestamp Microservice challenge.

When I test a URL with a unix or normal date in it, I get the right output on screen. But I can’t pass these tests:

  1. Your project can handle dates that can be successfully parsed by new Date(date_string)
  2. If the input date string is invalid, the api returns an object having the structure { error : "Invalid Date" }

I think I might be approaching it in the wrong way, but can’t figure it out, so any pointers/direction would be really welcome.

Here’s my project: https://boilerplate-project-timestamp.jesswebber.repl.co

Thanks!

Please add the url to your project, not (only) the rendered product. It won’t help much to look at the end result. One can reconstruct the url to the project but this will take time and reduce your chances of a good answer.

I just spent the past 3 days trying to get #1 to pass, and it came down to one simple thing that was left out of every explanation I found.

    // returns date_string converted to utc and unix time
    timestamp['unix'] = new Date(date_string).getTime();
    timestamp['utc'] = new Date(date_string).toUTCString();```
I tried many different things, even copy and paste source code for passing projects and even then they still would not pass because the source code was incorrect.  The second argument was missing, as show below:
```if (date_string.includes('-')

#2 was fixed by a similar statement

if(!timestamp['unix'] || !timestamp['utc'])

(GitHub - WiseGuise/timestamp-demo)

@alirezaghey - my bad. Here’s the entire project url: https://replit.com/@jesswebber/boilerplate-project-timestamp?v=1

@WiseGuise - thanks - will see if that works

I figured out the problem.
For test #1: I should have looked at the tests via developer tools. I hadn’t included this date format “05%20October%202011” in my if statement.
For test #2: I’d made a typo which was why it wasn’t passing!

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