/
router.js
34 lines (30 loc) · 878 Bytes
/
router.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const moment = require('moment');
module.exports = function(app){
app.get("/", function (request, response) {
response.sendFile(__dirname + '/views/index.html');
});
app.get('/:resource', function(req, res){
var data = req.params.resource;
var unix;
var natural;
if(moment(data).isValid()){
console.log("valido data");
unix = moment(data).format('X');
natural = moment(data).format("LL");
}
else if(moment.unix(data).isValid()){
console.log("valido unix");
unix = data;
natural = moment.unix(data).format("LL");
}
else{
console.log("non valido");
unix = natural = null;
}
/*if(unix === 'Invalid date')
unix = null;
if(natural === 'Invalid date')
natural = null;*/
res.send({ unix,natural });
})
}