Tell us what’s happening:
my code:
app.get("/api/:date?", (req, res) => {
const dateParam = req.params.date;
let date;
if (!dateParam) {
// create DateConstructor with the currant time
date = new Date();
}
else if () {
// the resat of the handler logic
}
const unix = date.getTime();
const utc = date.toUTCString();
res.json({
unix: unix,
utc: utc
})
return;
});
tests results
-
Passed: A request to
/api/:date?with a valid date should return a JSON object with aunixkey that is a Unix timestamp of the input date in milliseconds (as type Number) -
Passed: A request to
/api/:date?with a valid date should return a JSON object with autckey that is a string of the input date in the format:Thu, 01 Jan 1970 00:00:00 GMT -
Passed: A request to
/api/1451001600000should return{ unix: 1451001600000, utc: "Fri, 25 Dec 2015 00:00:00 GMT" } -
Passed: Your project can handle dates that can be successfully parsed by
new Date(date_string) -
Passed: If the input date string is invalid, the API returns an object having the structure
{ error : "Invalid Date" } -
Failed: An empty date parameter should return the current time in a JSON object with a
unixkey -
Failed: An empty date parameter should return the current time in a JSON object with a
utckey
the issue
is that when i run the server and test the response of the https://host-url/api i get the right json output
for example
{"unix":1709055160997,"utc":"Tue, 27 Feb 2024 17:32:40 GMT"}
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Challenge Information:
Back End Development and APIs Projects - Timestamp Microservice