Hello - I think I have completed the challenge but I am failing on one test… I’d really appreciate any help, I’m sure I’ve got an error somewhere but I’m not sure how to search for the answer to such a specific problem online / on the forums.
This is the test / output:
// running tests
It should handle a valid unix date, and return the correct unix timestamp
// tests completed
And my code is on Glitch here:
Or also below:
// Timestamp functionality...
app.get('/api/timestamp/:date_string?', (req, res) => {
// Get query from URL
let input = req.params.date_string;
let date;
// Create regex x2 for checks...
let regexUTC = /([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/;
let regexUnix = /\d{5,}/;
// Handle no given date
if (!input) {
date = new Date();
} else {
// Check if valid
if (regexUTC.test(input) == true) {
date = new Date(Date.parse(input));
} else if (regexUnix.test(input) == true) {
date = new Date(input * 1000);
console.log(date);
} else {
res.json({"error": "Invalid Date"});
}
};
res.json({"unix": date.getTime(), "utc" : date.toUTCString() });
});
Thanks!