I finished my project and the results seems good, but if someone can tell me something wrong about the thinking-process, method used or something else, I would really appreciate.
ISO-8601 format:
https://violet-timestamp.glitch.me/api/timestamp/2010-6-2
Timestamp format:
https://violet-timestamp.glitch.me/api/timestamp/323434827484
Now:
https://violet-timestamp.glitch.me/api/timestamp/
The code:
app.get("/api/timestamp/:date_string?", function(req, res){
let apiDate = req.params.date_string;
// if params === undefined throw new Date
if(apiDate === undefined){
let time = new Date();
res.send({unix: time.getTime(), utc: time.toUTCString()});
}
//check if there's a dash for the ISO-8601 format
//and parse the date, else perform a conversion from timestamp
if(apiDate.indexOf('-') !== -1){
let parsing = Date.parse(apiDate);
let utcDate = (new Date(parsing)).toUTCString();
res.send({unix: parsing, utc: utcDate});
} else {
let utcDate = (new Date(+apiDate)).toUTCString();
res.send({unix: +apiDate, utc: utcDate});
}
});