Hello, I am try to solve the Timestamp Microservice project. I ended the project with all the functionalities, and I pass the first 4 tasks, but not the last 2. I be grateful for any help.
Your code so far
let express = require('express');
let cors = require('cors');
let app = express();
app.use(cors());
app.set('port', process.env.PORT || 3000);
function ResponseDate(date){
return { "unix": date.getTime(), "utc": date.toUTCString() };
}
function ResponseTime(time) {
let date = new Date(time);
return ResponseDate(date);
}
function ResponseUnix(unix) {
let date = new Date(parseInt(unix));
return ResponseDate(date);
}
function ResponseCurrentTime(){
let date = new Date();
return ResponseDate(date);
}
app.get('/api/timestamp/:date?', function (req, res) {
if (req.params.date !== undefined) {
if ((new Date(parseInt(req.params.date * 1))).toString() !== "Invalid Date") {
res.json(ResponseUnix(parseInt(req.params.date)));
}
else if ((new Date(req.params.date)).toString() !== "Invalid Date") {
res.json(ResponseTime(req.params.date));
}
else {
res.json({ "error": "Invalid Date" });
}
}
else {
res.json(ResponseCurrentTime());
}
});
app.use(function (req, res, next) {
res.status(404);
res.send('NOT FOUND');
});
app.use(function (err, req, res, next) {
res.status(500);
res.send('ERROR');
});
app.listen(app.get('port'), function () {
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36
.
Challenge: Timestamp Microservice
Link to the challenge: