-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (38 loc) · 1.13 KB
/
index.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
48
const moment = require("moment-timezone");
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.use(bodyParser.json());
// normal operations
app.post("/invoke/realtime", (req, res) => {
const tz = req.body.arguments.Timezone;
res.json({
return: moment().tz(tz).format("dddd"),
});
});
// used for backtesting
app.post("/invoke/historic", (req, res) => {
// localize start and end of period
const tz = req.body.arguments.Timezone;
const [ start, end ] = req.body.period.map(d => moment(d).tz(tz));
// this will be our timeline
let ret = {
// day of week at start of period
[ start.format() ] : start.format("dddd")
};
// go to start of next day
let d = start.startOf("day").add(1, "days");
// add entry for each day in period
while (!d.isAfter(end)) {
ret[d.format()] = { value: d.format("dddd") };
d = d.add(1, "days");
}
// send response to extension server
res.json({
timeline: ret,
warn: [], // nothing bad happened
resolutions: [] // no machine-led decisions made
});
});
app.listen(5051, () =>
console.log("Extension Server Started successfully"))