Commit 79a8f4c6 authored by andreagerino's avatar andreagerino

Added finer timestamp management

parent 87684f5e
......@@ -8,7 +8,7 @@ var ObjectID = require('mongodb').ObjectID;
var assert = assert = require('assert');
// Connection URL
var mongoUrl = 'mongodb://icarus:icarus@localhost:27017/icarus';
var mongoUrl = 'mongodb://icarus:icarus@webdev.ewlab.di.unimi.it:27017/icarus';
//Connect to the server and intialise the pool
var icarusDb;
......@@ -58,6 +58,14 @@ router.post('/', function(req, res, next){
if(Object.keys(resource).length>0) {
var timestampContainer = getTimestampContainer(resource);
if(timestampContainer!=undefined){
preprocessTimestampContainer(timestampContainer);
}
collection.insertOne(resource, function (err, r) {
if (err != null) {
......@@ -86,4 +94,34 @@ router.post('/', function(req, res, next){
});
function getTimestampContainer(arg){
if(arg['timestamp']!=undefined&&(arg['timestamp']['utc']!=undefined)||arg['timestamp']['user']!=undefined)
return arg['timestamp'];
return undefined;
}
function preprocessTimestampContainer(container){
var utcSeconds = container['utc'];
var userSeconds = container['user'];
if(utcSeconds!=undefined){
var utcMsec = utcSeconds * 1000;
container['utc'] = new Date(utcMsec);
}
if(userSeconds!=undefined){
var userMsec = userSeconds * 1000;
container['user'] = new Date(userMsec);
}
}
module.exports = router;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment