Microservice TimeStamp - Date String test not passing

Tell us what’s happening:
I think my codes working fine , i even logged responses that freeCodeCamp is firing and will upload SS below. Based on the logs, only possible explanation I can give is because of the time zone difference maybe the test is expecting a different response and that is making it fail. Any kind of changes/rework are welcome. Thank you in advance.
PS : Since i can only upload 1 SS , heres the console log below when freeCodeCamp fired tests →

1 { date: ‘2016-12-25’ }
1 responseObj { unix: 1482624000000, utc: ‘Sun, 25 Dec 2016 00:00:00 GMT’ }
1 { date: ‘2016-12-25’ }
1 responseObj { unix: 1482624000000, utc: ‘Sun, 25 Dec 2016 00:00:00 GMT’ }
1 { date: ‘1451001600000’ }
1 responseObj { unix: 1451001600000, utc: ‘Fri, 25 Dec 2015 00:00:00 GMT’ }
1 { date: ‘05 October 2011’ }
1 responseObj { unix: 1317753000000, utc: ‘Tue, 04 Oct 2011 18:30:00 GMT’ }
1 { date: ‘this-is-not-a-date’ }
1 responseObj { error: ‘Invalid Date’ }
2 {}
2 {}

When you fire the below URL the response is different from the one I get(based on time zones i am guessing) ---->


{“unix”:1317772800000,“utc”:“Wed, 05 Oct 2011 00:00:00 GMT”}

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36

Challenge: Timestamp Microservice

Link to the challenge:

Well to see if it was specifically timezone issue I put a static condition and guess what?
My test passed instantly because of the fixed test cases freeCodeCamp is sending.

Would love to connect with anyone to talk more about this though. Cheers!

I would guess it’s because you are using toUTCString instead of just toDateString.

I double checked and my currently working projects use .toUTCString(), so I doubt that is the problem. My projects produce the same output as the example project. Your code looks correct, as far as that goes…

If I remember correctly for this project, the time zone shouldn’t matter unless your time zones are not set correctly. My suggestion is to check your system and user time zone settings to make sure all is correct and/or to post a link to a repl.it of your project (or similar) and let someone else try to replicate the error.

tried that but it didnt help. In the first comment I made on this post, I specifically set a static condition if you can see, and that actually made the project work and it got submitted. But that is because I know the specific Test case freeCodeCamp is sending.

for the input i.e ‘05 October 2011’, based on my IST timezone, I convert the date to a 5hr 30 mins difference which causes my UTC response to be 4th October 6.30pm which I think is not an acceptable response for the server , and hence the whole issue.

Every other test passes here except the date string one.

I thought so too but apparently it does matter because I cant find any other alternative to it.

Thanks in advance :slight_smile:

Good news: it works fine for me, without modification (exact times expected). Bad news: it’s likely your time zone settings.

Like you point out, the time is behind by 5.5 hours. Since you mention IST which is +5.5 hours relative to UTC, my guess is that you have your system time in IST but something on the system thinks it’s really in UTC, which puts your system’s UTC time behind 5.5 hours, which causes the browser time to be off, which fails the test. Fixing your system times hopefully will fix the problem.

For instance, my system stores and keeps system time in UTC while I have the time localized to Central (United States) Daylight Time (for now anyway…). You can either store and keep your system time in UTC and localize to IST or you can store and keep system time in IST but make sure the system knows it’s IST and not UTC, lest it assume that it’s actually UTC, which is probably the default.

1 Like

Yeah i was certain that the code is on point with the project needs, just needed to confirm the timezone difference as you stated out.
I fixed my system timezone settings and checked again and its working properly. Thank you for your time and help. :slight_smile:

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