I have completed all tests for this timestamp project besides the test ( Your project can handle dates that can be successfully parsed by new Date(date_string)
)
I am not sure why this does not pass and I am not even sure what the test is saying. Can someone please help .
// This takes a timestamp with an empty parameter and returns the current time since no date is there
app.get("/api/timestamp", function (req, res) {
// Make sure variables are inside the function so the update everytime website is refreshed.
let currentTime = Date().toString();
let currentUnixTime = Date.now();
res.json({ unix: currentUnixTime, utc: currentTime });
});
app.get("/api/timestamp/:date", function (req, res) {
let date_string = req.params.date;
let date;
// Create a js date if it is passed in year-month-day format
if (date_string.includes("-")) {
date = new Date(date_string);
}
// Create a js date if it is passed in unix format
else {
let millisecondDate_string = parseInt(date_string); // First convert data_string to milliseconds (needs to be converted into a number as Date() will only accept unix as a number)
date = new Date(millisecondDate_string); // Set the date in variable
}
// Handles if date input is invalid
if (date == "Invalid Date") {
res.json({ error: "Invalid Date" });
}
// Handles if date is valid
else {
res.json({
unix: date.valueOf(),
utc: date.toUTCString(),
});
}
});
Here is a link to my code: https://repl.it/@Hunterlacefield/boilerplate-project-timestamp#server.js
solution: https://boilerplate-project-timestamp.hunterlacefield.repl.co
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15
.
Challenge: Timestamp Microservice
Link to the challenge: