Tell us what’s happening:
The Challenge description describe the following need:
if the date string is empty it should be equivalent to trigger
new Date()
, i.e. the service uses the current timestamp.
How could an Parameter be empty if I use the :parameter notation?
If I don’t add the Date-String behind /api/timestamp
, the route doesn’t match anymore?!
So the only way is to create an additional route only for /api/timestamp
, right?!
Your code so far
app.get("/api/timestamp/:date_string", (req, res) => {
let reqDate = req.params.date_string;
let respDate;
reqDate = reqDate.indexOf('-') === -1 ? parseInt(reqDate) : (!reqDate ? new Date() : reqDate ) ;
respDate = new Date(parseInt(reqDate));
res.json({
"unix": respDate.getTime(),
"utc": respDate.toUTCString()
});
});
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36
.
Challenge: timestamp-microservice
Link to the challenge: