Back End Development and APIs Projects - Timestamp Microservice

Tell us what’s happening:

I got stuck while solving this challenge.

A request to /api/1451001600000 should return { unix: 1451001600000, utc: "Fri, 25 Dec 2015 00:00:00 GMT" }

If the input date string is invalid, the api returns an object having the structure { error : "Invalid Date" }

How can I do this?
The other part of challenge works well, but I can’t pass tests. At least it looks like the API response with correct object…
Your project link(s)

solution: https://replit.com/@andreypashinsky/boilerplate-project-timestampapi/2022-11-02

Your browser information:

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

Challenge: Back End Development and APIs Projects - Timestamp Microservice

Link to the challenge:

Your unix value isn’t correct. You can use getTime on the constructed date.

Math.round(new Date('2016-12-25')/1000)
1482624000

new Date('2016-12-25').getTime()
1482624000000

The params is a string and you can’t use 1451001600000 as a string for the date constructor.

new Date(1451001600000)
Fri Dec 25 2015 01:00:00 GMT+0100 (Central European Standard Time)

new Date('1451001600000')
Invalid Date

You are not checking what the date constructor is returning (valid or invalid date) and you are not returning the correct object for invalid dates.

If the input date string is invalid, the api returns an object having the structure { error : "Invalid Date" }

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