hi everyone, this is the code I wrote in order to pass the challenge:
// init project
var express = require('express');
var app = express();
var newDate, unixDate, utcDate;
var objDate = {};
const regexISO = new RegExp('([0-9]+(-[0-9]+)+)');
const regexUNIX = new RegExp('([0-9]+)');
app.get('/api/:date', (req, res) => {
objDate = {};
console.log(req.params)
const {date} = req.params;
//if it is ISO ---------------
if(regexISO.test(date)){
myDate = date.split("-");
newDate = new Date( myDate[0], myDate[1]-1, myDate[2]);
unixDate = newDate.getTime();
utcDate = new Date(date).toUTCString();
objDate['unix'] = unixDate;
objDate['utc'] = utcDate;
// console.log(newDate)
//if it is UTC ---------------
}else if(date.includes('GMT')){
unixDate = new Date(date).getTime()
objDate['utc'] = date;
objDate['unix'] = unixDate;
//if it is UNIX ------------
}else if(regexUNIX.test(date)){
utcDate = parseInt(date);
objDate['unix'] = utcDate;
utcDate = new Date(utcDate)
objDate['utc'] = utcDate.toUTCString();
//if is Inavalid ------------------
}else{
objDate = { error : "Invalid Date" }
}
//date = new Date(date);
console.log(objDate)
res.json(objDate);
}) ;
app.get('/api', (req, res) => {
objDate['utc'] = new Date().toUTCString();
objDate['unix'] = Date.now();
res.json(objDate);
})
And this is how it looks:
https://boilerplate-project-timestamp.davitboo.repl.co/
Also here all the files:
everytime I try to pass the challenges I just get the first check, the one that says:
“Passed:You should provide your own project, not the example URL.”
So what I am missing here?
Thank you in advance