-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
84 lines (72 loc) · 2.26 KB
/
test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const async = require("async");
const moment = require("moment");
const mongo = require("mongodb");
const client = mongo.MongoClient;
const generator = require("./generator");
const DB_URL = "mongodb://<username>:<password>@<hostname>:<port>/<database>";
const DB_COLLECTION = "tzoffset_test";
let db, res;
async.waterfall([
// connect to database
function (done) {
client.connect(DB_URL, (err, _db) => {
db = _db;
done(err);
});
},
//------------------------------------------------------
// drop test collection
//function (done) {
// db.collection(DB_COLLECTION).drop((err) => {
// done(err);
// });
//},
//------------------------------------------------------
//------------------------------------------------------
// insert test documents
//function (done) {
// const docs = [
// { time: new Date("2016-03-27T00:59:59Z"), name: "CET" },
// { time: new Date("2016-03-27T01:00:00Z"), name: "CEST" },
// { time: new Date("2016-03-27T01:00:01Z"), name: "CEST" },
// { time: new Date("2016-10-30T00:59:59Z"), name: "CEST" },
// { time: new Date("2016-10-30T01:00:00Z"), name: "CET" },
// { time: new Date("2016-10-30T01:00:01Z"), name: "CET" }
// ];
// db.collection(DB_COLLECTION).insert(docs, (err, res) => {
// done(err);
// })
//},
//------------------------------------------------------
// perform test query
function (done) {
const start = moment.utc("2016-01-01T00:00:00Z");
const end = moment.utc("2017-01-01T00:00:00Z");
const tz = "Europe/Berlin";
const cond = generator(start, end, tz);
db.collection(DB_COLLECTION).aggregate([
{
$project: {
name: "$name",
time_orig: "$time",
time_conv: cond
}
},
{
$limit: 100
}
]).toArray((err, _res) => {
res = _res;
done(err);
});
}
], (err) => {
if (err) {
console.error(err);
} else {
console.log(res);
}
if (db) {
db.close();
}
});