Tell us what’s happening:
Describe your issue in detail here.
Your code so far
Blockquote
app.get(“/api/timestamp/:date_string”, (req, res) => {
let dateString = req.params.date_string;
//A 4 digit number is a valid ISO-8601 for the beginning of that year
//5 digits or more must be a unix time, until we reach a year 10,000 problem
if (/\d{5,}/.test(dateString)) {
let dateInt = parseInt(dateString);
//Date regards numbers as unix timestamps, strings are processed differently
res.json({ unix: dateString, utc: new Date(dateInt).toUTCString() });
} else {
let dateObject = new Date(dateString);
if (dateObject.toString() === "Invalid Date") {
res.json({ error: "Invalid Date" });
} else {
res.json({ unix: dateObject.valueOf(), utc: dateObject.toUTCString() });
}
}
});
Blockquote
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 11; SM-M127F) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.85 Mobile Safari/537.36
Challenge: Timestamp Microservice
Link to the challenge: