I took a quick glance. I’m not sure but I would add other test links to your index.html for testing with invalid dates. such as month 13 or day over 31 etc and see what you get. I noticed in your code
app.get("/api/:date", (req, res) => {
let dateString = req.params.date;
if (!isNaN(Date.parse(dateString))) {
let dateObject = new Date(dateString);
res.json({ unix: dateObject.valueOf(), utc: dateObject.toUTCString() });
} else if (/\d{5,}/.test(dateString)) {
let dateInt = parseInt(dateString);
res.json({ unix: dateInt, utc: new Date(dateInt).toUTCString() });
} else {
res.json({ error: "Invalid Date" });
}
});
the regex only checks for digits. That does not mean those digits are valid months or days?
edit
I should also mention fire up your replit and submit link. My connection sometimes lags so much I have to submit multiple times for the tests to pass.
Thank you so much. But later I found the solution. I was busy today I forgot to delete this post.
The code you quoted is the final code which is working