-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (44 loc) · 1.37 KB
/
app.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
35
36
37
38
39
40
41
42
43
44
45
46
47
var path=require('path');
var express=require('express');
var app=express();
var bodyparser=require('body-parser');
app.route('/:date')
.get(function(req, res) {
// res.sendFile(process.cwd() + '/views/index.html');
var unix=null,naturaldate=null;
//console.log(parseInt(timestamp),timestamp)
let timestamp=req.params.date;
if(!isNaN(timestamp)){
let parsetime=new Date(parseInt(timestamp))
console.log(parsetime);
if(parsetime=='Invalid Date'){
console.log("got invalid date")
send_response(null,null,res);
}
let parsenaturaldate=parsetime.toDateString().split(" ").slice(1);
let year=parsenaturaldate.splice(2,0,',');
year=parsenaturaldate.splice(1,0,' ')
naturaldate=parsenaturaldate.join("")
console.log(naturaldate)
unix=parseInt(timestamp)
send_response(unix,naturaldate,res);
}else {
unix=Date.parse(timestamp);
console.log(unix);
if(!isNaN(unix))
naturaldate=timestamp
else
return send_response(null,null,res);
send_response(unix,naturaldate,res);
}
})
function send_response(unix,naturaldate,res){
console.log(unix,naturaldate)
res.json({
"unix":unix,
"natural":naturaldate
})
}
app.listen(8083||process.env.PORT,()=>{
console.log("server is listening")
})